summaryrefslogtreecommitdiffstats
path: root/chrome/browser/user_data_manager.h
diff options
context:
space:
mode:
authormunjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-03 23:52:03 +0000
committermunjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-03 23:52:03 +0000
commitf253006b157f9c917fba21a7312290aaa2e889e7 (patch)
tree377183f9511bed141b5fd7a706c3407a122540d9 /chrome/browser/user_data_manager.h
parentdadacf06556b4f63a62ec3cea91d7fc5abccd67c (diff)
downloadchromium_src-f253006b157f9c917fba21a7312290aaa2e889e7.zip
chromium_src-f253006b157f9c917fba21a7312290aaa2e889e7.tar.gz
chromium_src-f253006b157f9c917fba21a7312290aaa2e889e7.tar.bz2
Chromium-MultiProfile-Prototype
Summary ======= Implement a prototype of multiple profiles in Chrome by utilizing the functionality of user-data-dir command line flag that already exists. A profile in this case is an umbrella for all user data including cookies, history, bookmarks, settings, etc. Each profile gives the user a separation of all these data elements. User Interface ============== - Wrench > "New window in profile" menu item, with sub-menu items. This new menu item has sub menu items for each existing profile, for up to 9 profiles, and one more sub menu item to launch a window in a new profile. The 9 sub-menu items also have the accelerators like CTRL + SHIFT + 1, CTRL + SHIFT + 2, etc. If there are more than 9 profiles, we will also show an extra sub-menu item, "Other...". - New Profile dialog box This dialog box is shown to the use when (s)he clicks Wrench > New window in profile > <New Profile>. It lets the user specify a profile name, and also shows a checkbox to create a desktop shortcut to launch Chrome in that profile. - Choose profile dialog box This dialog box lets the user select a profile from a drop down to open a new window in. It also has an item <New Profile> in the drop down, selecting which will show the new profile dialog box mentioned above. CTRL + M shortcut also launches this dialog box. Code Organization ================= chrome\browser\user_data_dir_profile_manager.h/.cc: This class provides an abstraction of profiles on top of the user data dir command line flag. chrome\browser\views\user_data_dir_new_profile_dialog.h/.cc New profile dialog box code. chrome\browser\views\user_data_dir_profiles_dialog.h/.cc Choose profile dialog box code. Review URL: http://codereview.chromium.org/12895 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6333 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/user_data_manager.h')
-rw-r--r--chrome/browser/user_data_manager.h149
1 files changed, 149 insertions, 0 deletions
diff --git a/chrome/browser/user_data_manager.h b/chrome/browser/user_data_manager.h
new file mode 100644
index 0000000..f5e4522
--- /dev/null
+++ b/chrome/browser/user_data_manager.h
@@ -0,0 +1,149 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This class encapsulates the implementation of multiple profiles by using
+// the user-data-dir functionality.
+
+#ifndef CHROME_BROWSER_USER_DATA_MANAGER_H_
+#define CHROME_BROWSER_USER_DATA_MANAGER_H_
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/ref_counted.h"
+
+class MessageLoop;
+
+// Provides an abstraction of profiles on top of the user data directory
+// feature. Given the root of the user data directories, it provides
+// functionality to enumerate the existing profiles and start Chrome in a
+// given profile.
+// Also holds a shared instance of its own for convenience though it's not a
+// singleton class. The shared instance should be created by the main thread,
+// then other threads can access and use the shared instance.
+class UserDataManager {
+ public:
+ // Creates the shared instance of this class. This method is not thread-safe,
+ // so the shared instance should be created on the main thread.
+ static void Create();
+
+ // Returns the shared instance. CreateInstance must be called before callling
+ // this method.
+ static UserDataManager* Get();
+
+ // Creates a new instance with the given root folder for storing user data
+ // folders.
+ explicit UserDataManager(const std::wstring& user_data_root);
+
+ ~UserDataManager();
+
+ // Returns the name of the current profile.
+ std::wstring current_profile_name() const { return current_profile_name_; }
+
+ // Returns whether the current profile is the default profile or not.
+ bool is_current_profile_default() const {
+ return is_current_profile_default_;
+ }
+
+ // Populates the given vector with a list of all the profiles.
+ // This function should be called on the file thread.
+ void GetProfiles(std::vector<std::wstring>* profiles) const;
+
+ // Creates a desktop shortcut for the given profile name.
+ // Returns false if the shortcut creation fails; true otherwise.
+ bool CreateDesktopShortcutForProfile(const std::wstring& profile_name) const;
+
+ // Starts a new Chrome instance in the given profile name.
+ void LaunchChromeForProfile(const std::wstring& profile_name) const;
+
+ // Starts a new Chrome instance in the profile with the given index. The
+ // index is zero based, and refers to the position of the profile in the
+ // list of profile names in alphabetical order.
+ // This method launches Chrome asynchornously since it enumerates profiles
+ // on a separate thread.
+ void LaunchChromeForProfile(int index) const;
+
+ private:
+ // Gets the name of the profile from the name of the folder.
+ // Returns false if the folder does not correspond to a profile folder, true
+ // otherwise.
+ static bool GetProfileNameFromFolderName(const std::wstring& folder_name,
+ std::wstring* profile_name);
+
+ // Returns the name of the folder from the name of the profile.
+ static std::wstring GetFolderNameFromProfileName(
+ const std::wstring& profile_name);
+
+ // Returns the path of the user data folder for the given profile.
+ std::wstring GetUserDataFolderForProfile(
+ const std::wstring& profile_name) const;
+
+ // Returns the command to start the app in the given profile.
+ std::wstring GetCommandForProfile(const std::wstring& profile_name) const;
+
+ // Shared instance.
+ static UserDataManager* instance_;
+
+ // Root folder.
+ std::wstring user_data_root_;
+
+ // Current user data folder.
+ std::wstring current_folder_name_;
+
+ // Whether the current profile is the default profile.
+ bool is_current_profile_default_;
+
+ // Current profile name.
+ std::wstring current_profile_name_;
+
+ DISALLOW_COPY_AND_ASSIGN(UserDataManager);
+};
+
+// Helper class to enumerate the profiles asynchronously on the file thread.
+// It calls the given delegate instance when the enumeration is complete.
+// USAGE: Create an instance of the helper with a delegate instance, call the
+// asynchronous method GetProfiles. The delegate instance will be called when
+// enumerating profiles is done.
+// IMPORTANT: It's the responsibility of the caller to call OnDelegateDeleted
+// method when the delegate instance is deleted. Typically OnDelegateDeleted
+// should be called in the destructor of the delegate. This is the way to
+// tell the helper to not call the delegate when enumerating profiles is done.
+class GetProfilesHelper
+ : public base::RefCountedThreadSafe<GetProfilesHelper> {
+ public:
+ // Interface the delegate classes should implement.
+ class Delegate {
+ public:
+ virtual void OnGetProfilesDone(
+ const std::vector<std::wstring>& profiles) = 0;
+ virtual ~Delegate() { }
+ };
+
+ explicit GetProfilesHelper(Delegate* delegate);
+
+ // Asynchronous call to get the list of profiles. Calls the delegate when done
+ // on either the given target loop or the message loop on which this function
+ // is called if target loop is NULL.
+ void GetProfiles(MessageLoop* target_loop);
+
+ // Records that the delegate is deleted.
+ void OnDelegateDeleted();
+
+ private:
+ // Helper to get the profiles from user data manager.
+ void GetProfilesFromManager();
+
+ // Helper to invoke the delegate.
+ void InvokeDelegate(std::vector<std::wstring>* profiles);
+
+ // Delegate to call.
+ Delegate* delegate_;
+ // Message loop to post tasks on completion of loading profiles.
+ MessageLoop* message_loop_;
+
+ DISALLOW_COPY_AND_ASSIGN(GetProfilesHelper);
+};
+
+#endif // CHROME_BROWSER_USER_DATA_MANAGER_H_