| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This class keeps track of the currently-active profiles in the runtime. | 5 // This class keeps track of the currently-active profiles in the runtime. |
| 6 | 6 |
| 7 #ifndef CHROME_BROWSER_PROFILE_MANAGER_H__ | 7 #ifndef CHROME_BROWSER_PROFILE_MANAGER_H__ |
| 8 #define CHROME_BROWSER_PROFILE_MANAGER_H__ | 8 #define CHROME_BROWSER_PROFILE_MANAGER_H__ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "app/system_monitor.h" | 15 #include "app/system_monitor.h" |
| 16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 17 #include "base/file_path.h" | 17 #include "base/file_path.h" |
| 18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 19 #include "base/non_thread_safe.h" | 19 #include "base/non_thread_safe.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "chrome/browser/profile.h" | 21 #include "chrome/browser/profile.h" |
| 22 #include "chrome/common/notification_observer.h" | 22 #include "chrome/common/notification_observer.h" |
| 23 #include "chrome/common/notification_registrar.h" | 23 #include "chrome/common/notification_registrar.h" |
| 24 | 24 |
| 25 // This is a small storage class that simply represents some metadata about | |
| 26 // profiles that are available in the current user data directory. | |
| 27 // These are cached in local state so profiles don't need to be scanned | |
| 28 // for their metadata on every launch. | |
| 29 class AvailableProfile { | |
| 30 public: | |
| 31 AvailableProfile(const std::wstring& name, | |
| 32 const std::wstring& id, | |
| 33 const FilePath& directory) | |
| 34 : name_(name), id_(id), directory_(directory) {} | |
| 35 | |
| 36 // Decodes a DictionaryValue into an AvailableProfile | |
| 37 static AvailableProfile* FromValue(DictionaryValue* value) { | |
| 38 DCHECK(value); | |
| 39 std::wstring name, id; | |
| 40 FilePath::StringType directory; | |
| 41 value->GetString(L"name", &name); | |
| 42 value->GetString(L"id", &id); | |
| 43 value->GetString(L"directory", &directory); | |
| 44 return new AvailableProfile(name, id, FilePath(directory)); | |
| 45 } | |
| 46 | |
| 47 // Encodes this AvailableProfile into a new DictionaryValue | |
| 48 DictionaryValue* ToValue() { | |
| 49 DictionaryValue* value = new DictionaryValue; | |
| 50 value->SetString(L"name", name_); | |
| 51 value->SetString(L"id", id_); | |
| 52 value->SetString(L"directory", directory_.value()); | |
| 53 return value; | |
| 54 } | |
| 55 | |
| 56 std::wstring name() const { return name_; } | |
| 57 std::wstring id() const { return id_; } | |
| 58 FilePath directory() const { return directory_; } | |
| 59 | |
| 60 private: | |
| 61 std::wstring name_; // User-visible profile name | |
| 62 std::wstring id_; // Profile identifier | |
| 63 FilePath directory_; // Subdirectory containing profile (not full path) | |
| 64 | |
| 65 DISALLOW_COPY_AND_ASSIGN(AvailableProfile); | |
| 66 }; | |
| 67 | |
| 68 class ProfileManager : public NonThreadSafe, | 25 class ProfileManager : public NonThreadSafe, |
| 69 public SystemMonitor::PowerObserver, | 26 public SystemMonitor::PowerObserver, |
| 70 public NotificationObserver { | 27 public NotificationObserver { |
| 71 public: | 28 public: |
| 72 ProfileManager(); | 29 ProfileManager(); |
| 73 virtual ~ProfileManager(); | 30 virtual ~ProfileManager(); |
| 74 | 31 |
| 75 // Invokes ShutdownSessionService() on all profiles. | 32 // Invokes ShutdownSessionService() on all profiles. |
| 76 static void ShutdownSessionServices(); | 33 static void ShutdownSessionServices(); |
| 77 | 34 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 105 // These allow iteration through the current list of profiles. | 62 // These allow iteration through the current list of profiles. |
| 106 typedef std::vector<Profile*> ProfileVector; | 63 typedef std::vector<Profile*> ProfileVector; |
| 107 typedef ProfileVector::iterator iterator; | 64 typedef ProfileVector::iterator iterator; |
| 108 typedef ProfileVector::const_iterator const_iterator; | 65 typedef ProfileVector::const_iterator const_iterator; |
| 109 | 66 |
| 110 iterator begin() { return profiles_.begin(); } | 67 iterator begin() { return profiles_.begin(); } |
| 111 const_iterator begin() const { return profiles_.begin(); } | 68 const_iterator begin() const { return profiles_.begin(); } |
| 112 iterator end() { return profiles_.end(); } | 69 iterator end() { return profiles_.end(); } |
| 113 const_iterator end() const { return profiles_.end(); } | 70 const_iterator end() const { return profiles_.end(); } |
| 114 | 71 |
| 115 typedef std::vector<AvailableProfile*> AvailableProfileVector; | |
| 116 | |
| 117 // PowerObserver notifications | 72 // PowerObserver notifications |
| 118 void OnSuspend(); | 73 void OnSuspend(); |
| 119 void OnResume(); | 74 void OnResume(); |
| 120 | 75 |
| 121 // NotificationObserver implementation. | 76 // NotificationObserver implementation. |
| 122 virtual void Observe(NotificationType type, | 77 virtual void Observe(NotificationType type, |
| 123 const NotificationSource& source, | 78 const NotificationSource& source, |
| 124 const NotificationDetails& details); | 79 const NotificationDetails& details); |
| 125 | 80 |
| 126 // ------------------ static utility functions ------------------- | 81 // ------------------ static utility functions ------------------- |
| 127 | 82 |
| 128 // Returns the path to the default profile directory, based on the given | 83 // Returns the path to the default profile directory, based on the given |
| 129 // user data directory. | 84 // user data directory. |
| 130 static FilePath GetDefaultProfileDir(const FilePath& user_data_dir); | 85 static FilePath GetDefaultProfileDir(const FilePath& user_data_dir); |
| 131 | 86 |
| 132 // Returns the path to the preferences file given the user profile directory. | 87 // Returns the path to the preferences file given the user profile directory. |
| 133 static FilePath GetProfilePrefsPath(const FilePath& profile_dir); | 88 static FilePath GetProfilePrefsPath(const FilePath& profile_dir); |
| 134 | 89 |
| 135 // Tries to determine whether the given path represents a profile | 90 // Tries to determine whether the given path represents a profile |
| 136 // directory, and returns true if it thinks it does. | 91 // directory, and returns true if it thinks it does. |
| 137 static bool IsProfile(const FilePath& path); | 92 static bool IsProfile(const FilePath& path); |
| 138 | 93 |
| 139 // If a profile with the given path is currently managed by this object, | 94 // If a profile with the given path is currently managed by this object, |
| 140 // return a pointer to the corresponding Profile object; | 95 // return a pointer to the corresponding Profile object; |
| 141 // otherwise return NULL. | 96 // otherwise return NULL. |
| 142 Profile* GetProfileByPath(const FilePath& path) const; | 97 Profile* GetProfileByPath(const FilePath& path) const; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 155 // Adds a pre-existing Profile object to the set managed by this | 110 // Adds a pre-existing Profile object to the set managed by this |
| 156 // ProfileManager. This ProfileManager takes ownership of the Profile. | 111 // ProfileManager. This ProfileManager takes ownership of the Profile. |
| 157 // The Profile should not already be managed by this ProfileManager. | 112 // The Profile should not already be managed by this ProfileManager. |
| 158 // Returns true if the profile was added, false otherwise. | 113 // Returns true if the profile was added, false otherwise. |
| 159 bool AddProfile(Profile* profile, bool init_extensions); | 114 bool AddProfile(Profile* profile, bool init_extensions); |
| 160 | 115 |
| 161 // We keep a simple vector of profiles rather than something fancier | 116 // We keep a simple vector of profiles rather than something fancier |
| 162 // because we expect there to be a small number of profiles active. | 117 // because we expect there to be a small number of profiles active. |
| 163 ProfileVector profiles_; | 118 ProfileVector profiles_; |
| 164 | 119 |
| 165 AvailableProfileVector available_profiles_; | |
| 166 | |
| 167 NotificationRegistrar registrar_; | 120 NotificationRegistrar registrar_; |
| 168 | 121 |
| 169 // Indicates that a user has logged in and that the profile specified | 122 // Indicates that a user has logged in and that the profile specified |
| 170 // in the --login-profile command line argument should be used as the | 123 // in the --login-profile command line argument should be used as the |
| 171 // default. | 124 // default. |
| 172 bool logged_in_; | 125 bool logged_in_; |
| 173 | 126 |
| 174 DISALLOW_COPY_AND_ASSIGN(ProfileManager); | 127 DISALLOW_COPY_AND_ASSIGN(ProfileManager); |
| 175 }; | 128 }; |
| 176 | 129 |
| 177 #endif // CHROME_BROWSER_PROFILE_MANAGER_H__ | 130 #endif // CHROME_BROWSER_PROFILE_MANAGER_H__ |
| OLD | NEW |