Home | History | Annotate | Download | only in profiles
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_PROFILES_PROFILE_SHORTCUT_MANAGER_WIN_H_
      6 #define CHROME_BROWSER_PROFILES_PROFILE_SHORTCUT_MANAGER_WIN_H_
      7 
      8 #include "base/callback.h"
      9 #include "chrome/browser/profiles/profile_shortcut_manager.h"
     10 #include "content/public/browser/notification_observer.h"
     11 #include "content/public/browser/notification_registrar.h"
     12 
     13 class BrowserDistribution;
     14 
     15 // Internal free-standing functions that are exported here for testing.
     16 namespace profiles {
     17 namespace internal {
     18 
     19 // Returns the full path to the profile icon file.
     20 base::FilePath GetProfileIconPath(const base::FilePath& profile_path);
     21 
     22 // Returns the default shortcut filename for the given profile name,
     23 // given |distribution|. Returns a filename appropriate for a
     24 // single-user installation if |profile_name| is empty.
     25 string16 GetShortcutFilenameForProfile(const string16& profile_name,
     26                                        BrowserDistribution* distribution);
     27 
     28 // Returns the command-line flags to launch Chrome with the given profile.
     29 string16 CreateProfileShortcutFlags(const base::FilePath& profile_path);
     30 
     31 }  // namespace internal
     32 }  // namespace profiles
     33 
     34 class ProfileShortcutManagerWin : public ProfileShortcutManager,
     35                                   public ProfileInfoCacheObserver,
     36                                   public content::NotificationObserver {
     37  public:
     38   // Specifies whether only the existing shortcut should be updated, a new
     39   // shortcut should be created if none exist, or only the icon for this profile
     40   // should be created in the profile directory.
     41   enum CreateOrUpdateMode {
     42     UPDATE_EXISTING_ONLY,
     43     CREATE_WHEN_NONE_FOUND,
     44     CREATE_OR_UPDATE_ICON_ONLY,
     45   };
     46   // Specifies whether non-profile shortcuts should be updated.
     47   enum NonProfileShortcutAction {
     48     IGNORE_NON_PROFILE_SHORTCUTS,
     49     UPDATE_NON_PROFILE_SHORTCUTS,
     50   };
     51 
     52   explicit ProfileShortcutManagerWin(ProfileManager* manager);
     53   virtual ~ProfileShortcutManagerWin();
     54 
     55   // ProfileShortcutManager implementation:
     56   virtual void CreateOrUpdateProfileIcon(
     57       const base::FilePath& profile_path,
     58       const base::Closure& callback) OVERRIDE;
     59   virtual void CreateProfileShortcut(
     60       const base::FilePath& profile_path) OVERRIDE;
     61   virtual void RemoveProfileShortcuts(
     62       const base::FilePath& profile_path) OVERRIDE;
     63   virtual void HasProfileShortcuts(
     64       const base::FilePath& profile_path,
     65       const base::Callback<void(bool)>& callback) OVERRIDE;
     66 
     67   // ProfileInfoCacheObserver implementation:
     68   virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE;
     69   virtual void OnProfileWasRemoved(const base::FilePath& profile_path,
     70                                    const string16& profile_name) OVERRIDE;
     71   virtual void OnProfileNameChanged(const base::FilePath& profile_path,
     72                                     const string16& old_profile_name) OVERRIDE;
     73   virtual void OnProfileAvatarChanged(
     74       const base::FilePath& profile_path) OVERRIDE;
     75 
     76   // content::NotificationObserver implementation:
     77   virtual void Observe(int type,
     78                        const content::NotificationSource& source,
     79                        const content::NotificationDetails& details) OVERRIDE;
     80 
     81  private:
     82   // Gives the profile path of an alternate profile than |profile_path|.
     83   // Must only be called when the number profiles is 2.
     84   base::FilePath GetOtherProfilePath(const base::FilePath& profile_path);
     85 
     86   // Creates or updates shortcuts for the profile at |profile_path| according
     87   // to the specified |create_mode| and |action|. This will always involve
     88   // creating or updating the icon file for this profile.
     89   // Calls |callback| on successful icon creation.
     90   void CreateOrUpdateShortcutsForProfileAtPath(
     91       const base::FilePath& profile_path,
     92       CreateOrUpdateMode create_mode,
     93       NonProfileShortcutAction action,
     94       const base::Closure& callback);
     95 
     96   ProfileManager* profile_manager_;
     97 
     98   content::NotificationRegistrar registrar_;
     99 
    100   DISALLOW_COPY_AND_ASSIGN(ProfileShortcutManagerWin);
    101 };
    102 
    103 #endif  // CHROME_BROWSER_PROFILES_PROFILE_SHORTCUT_MANAGER_WIN_H_
    104