summaryrefslogtreecommitdiff
path: root/profile.h
diff options
context:
space:
mode:
authormukesh agrawal <quiche@chromium.org>2015-08-28 15:29:52 -0700
committermukesh agrawal <quiche@google.com>2015-09-21 17:49:03 -0700
commite48186532acb04b9e11efc9b9334dd555ffcae29 (patch)
tree1127f42188011c7124c898623d3cfae49f980ced /profile.h
parent44b9934a9528c0c19c82e0c6a79642eefeb54ea2 (diff)
downloadshill-e48186532acb04b9e11efc9b9334dd555ffcae29.tar.gz
shill: use 'json' extension for JsonStore profiles
To avoid any confusion between files using different formats, we want KeyFileStore profiles and JsonStore profiles to have different names. So add '.json' to the file name when using JsonStore as the backend. Note: initially, I wanted to isolate the ENABLE_JSON_STORE dependent code to just StoreFactory. But I've come to change my mind on that. The reason for my change of mind is that {Default}ProfileTest checks the actual path that will be used when writing the file. And that seems like an appropriate thing to test. But, to do that, {Default}ProfileTest needs to know when backend we're using. So we need ENABLE_JSON_STORE checks in {Default}ProfileTest. And once we've done that, it seems silly, and unnatural, to hide this information from Profile. Along the way: - Move path computation from InitStorage() and RemoveStorage(), into the {Default}Profile constructor. This makes the code slightly simpler (removing a virtual method) and shorter. - Provide a method for tests to query the path that Profile would use, so that we don't duplicate path computation logic. - Remove |storage_path_| field, since it was only needed to compute the path of the persistent file. While there: - Rename |store_path| argument to DefaultProfile ctor. It's unclear whether such a "path" should refer to a directory or a file. - Rename |user_storage_directory| argument to Profile ctor. This name makes no sense when the Profile ctor is being called from the DefaultProfile ctor. Bug: 23561491 TEST="USE=json_store FEATURES=test emerge-samus shill" Change-Id: I9b7e9b04dc80c89c20ea43158ed293b8a50fadbf
Diffstat (limited to 'profile.h')
-rw-r--r--profile.h32
1 files changed, 19 insertions, 13 deletions
diff --git a/profile.h b/profile.h
index a68b0575..9d388b6a 100644
--- a/profile.h
+++ b/profile.h
@@ -75,7 +75,7 @@ class Profile : public base::RefCounted<Profile> {
Metrics* metrics,
Manager* manager,
const Identifier& name,
- const base::FilePath& user_storage_directory,
+ const base::FilePath& storage_directory,
bool connect_to_rpc);
virtual ~Profile();
@@ -210,23 +210,29 @@ class Profile : public base::RefCounted<Profile> {
virtual bool IsDefault() const { return false; }
protected:
- // Protected getters
+ // Returns the persistent store file path for a Profile with the
+ // given |storage_dir| and |profile_name|. Provided as a static
+ // method, so that tests can use this logic without having to
+ // instantiate a Profile.
+ static base::FilePath GetFinalStoragePath(
+ const base::FilePath& storage_dir,
+ const Identifier& profile_name);
+
Metrics* metrics() const { return metrics_; }
Manager* manager() const { return manager_; }
StoreInterface* storage() { return storage_.get(); }
- const base::FilePath& storage_path() { return storage_path_; }
-
- // Sets |path| to the persistent store file path for a profile identified by
- // |name_|. Returns true on success, and false if unable to determine an
- // appropriate file location. |name_| must be a valid identifier,
- // possibly parsed and validated through Profile::ParseIdentifier.
- //
- // In the default implementation, |name_.user| cannot be empty, because
- // all regular profiles should be associated with a user.
- virtual bool GetStoragePath(base::FilePath* path);
+ const base::FilePath& persistent_profile_path() {
+ return persistent_profile_path_;
+ }
+ void set_persistent_profile_path(const base::FilePath& path) {
+ persistent_profile_path_ = path;
+ }
private:
+ friend class ManagerTest;
friend class ProfileAdaptorInterface;
+ FRIEND_TEST(ManagerTest, CreateDuplicateProfileWithMissingKeyfile);
+ FRIEND_TEST(ManagerTest, RemoveProfile);
FRIEND_TEST(ProfileTest, DeleteEntry);
FRIEND_TEST(ProfileTest, GetStoragePath);
FRIEND_TEST(ProfileTest, IsValidIdentifierToken);
@@ -243,7 +249,7 @@ class Profile : public base::RefCounted<Profile> {
Metrics* metrics_;
Manager* manager_;
ControlInterface* control_interface_;
- const base::FilePath storage_path_; // Path to user profile directory.
+ base::FilePath persistent_profile_path_;
// Shared with |adaptor_| via public getter.
PropertyStore store_;