diff options
author | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-26 20:11:17 +0000 |
---|---|---|
committer | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-26 20:11:17 +0000 |
commit | 7b5f89c4c97cd2ce098155b91018aca58d0e8b6d (patch) | |
tree | 93af3aacc8449990a12e1be1858782c5b4716401 | |
parent | c30a47e1f4af8c933fd131c0a4d2b1425a6992c4 (diff) | |
download | chromium_src-7b5f89c4c97cd2ce098155b91018aca58d0e8b6d.zip chromium_src-7b5f89c4c97cd2ce098155b91018aca58d0e8b6d.tar.gz chromium_src-7b5f89c4c97cd2ce098155b91018aca58d0e8b6d.tar.bz2 |
Add a header file for ProfileShortcutManagerWin and various clean up.
- Rename GetShortcutNameForProfile() to GetShortcutFilenameForProfile()
and make it standalone in a namespace that is exposed for testing.
- Remove various unused headers.
- Various other clean ups
BUG=none
TEST=compiles and existing unit tests
R=gab,sail
TBR=sky
Review URL: https://codereview.chromium.org/11414135
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169474 0039d316-1c4b-4281-b951-d872f2087c98
6 files changed, 107 insertions, 84 deletions
diff --git a/chrome/browser/profiles/profile_shortcut_manager.h b/chrome/browser/profiles/profile_shortcut_manager.h index 29ae7ba..a8886f7 100644 --- a/chrome/browser/profiles/profile_shortcut_manager.h +++ b/chrome/browser/profiles/profile_shortcut_manager.h @@ -22,7 +22,6 @@ class ProfileShortcutManager { static bool IsFeatureEnabled(); static ProfileShortcutManager* Create(ProfileManager* manager); - static string16 GetShortcutNameForProfile(const string16& profile_name); protected: ProfileShortcutManager(); diff --git a/chrome/browser/profiles/profile_shortcut_manager_stub.cc b/chrome/browser/profiles/profile_shortcut_manager_stub.cc index 858251e..b1a0a0e 100644 --- a/chrome/browser/profiles/profile_shortcut_manager_stub.cc +++ b/chrome/browser/profiles/profile_shortcut_manager_stub.cc @@ -14,10 +14,3 @@ ProfileShortcutManager* ProfileShortcutManager::Create( ProfileManager* manager) { return NULL; } - -// static -string16 ProfileShortcutManager::GetShortcutNameForProfile( - const string16& profile_name) { - NOTREACHED(); - return string16(); -} diff --git a/chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc b/chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc index 4a4234e..e4ddc55 100644 --- a/chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc +++ b/chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc @@ -10,21 +10,18 @@ #include "base/test/scoped_path_override.h" #include "base/string16.h" #include "base/test/test_shortcut_win.h" -#include "base/utf_string_conversions.h" #include "base/win/shortcut.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_shortcut_manager.h" +#include "chrome/browser/profiles/profile_shortcut_manager_win.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/shell_util.h" #include "chrome/test/base/testing_browser_process.h" -#include "chrome/test/base/testing_pref_service.h" #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile_manager.h" #include "content/public/test/test_browser_thread.h" -#include "grit/theme_resources.h" #include "testing/gtest/include/gtest/gtest.h" -#include "ui/base/resource/resource_bundle.h" using content::BrowserThread; @@ -56,7 +53,7 @@ class ProfileShortcutManagerTest : public testing::Test { dest_path_ = profile_info_cache_->GetUserDataDir(); dest_path_ = dest_path_.Append(FILE_PATH_LITERAL("My profile")); file_util::CreateDirectoryW(dest_path_); - profile_name_ = ASCIIToUTF16("My profile"); + profile_name_ = L"My profile"; ASSERT_TRUE(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution_, @@ -67,7 +64,7 @@ class ProfileShortcutManagerTest : public testing::Test { second_dest_path_ = second_dest_path_.Append(FILE_PATH_LITERAL("My profile 2")); file_util::CreateDirectoryW(second_dest_path_); - second_profile_name_ = ASCIIToUTF16("My profile 2"); + second_profile_name_ = L"My profile 2"; } virtual void TearDown() OVERRIDE { @@ -125,7 +122,8 @@ class ProfileShortcutManagerTest : public testing::Test { // Returns the default shortcut path for this profile. FilePath GetDefaultShortcutPathForProfile(const string16& profile_name) { return shortcuts_directory_.Append( - ProfileShortcutManager::GetShortcutNameForProfile(profile_name)); + profiles::internal::GetShortcutFilenameForProfile(profile_name, + distribution_)); } // Returns true if the shortcut for this profile exists. @@ -171,12 +169,14 @@ TEST_F(ProfileShortcutManagerTest, ShortcutFilename) { const string16 expected_name = kProfileName + L" - " + distribution_->GetAppShortCutName() + installer::kLnkExt; EXPECT_EQ(expected_name, - ProfileShortcutManager::GetShortcutNameForProfile(kProfileName)); + profiles::internal::GetShortcutFilenameForProfile(kProfileName, + distribution_)); } TEST_F(ProfileShortcutManagerTest, UnbadgedShortcutFilename) { EXPECT_EQ(distribution_->GetAppShortCutName() + installer::kLnkExt, - ProfileShortcutManager::GetShortcutNameForProfile(string16())); + profiles::internal::GetShortcutFilenameForProfile(string16(), + distribution_)); } TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) { @@ -207,7 +207,7 @@ TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) { // Cause an update in ProfileShortcutManager by modifying the profile info // cache. - string16 new_profile_name = ASCIIToUTF16("New Profile Name"); + const string16 new_profile_name = L"New Profile Name"; profile_info_cache_->SetNameOfProfileAtIndex( profile_info_cache_->GetIndexOfProfileWithPath(second_dest_path_), new_profile_name); @@ -322,7 +322,7 @@ TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsAfterProfileRename) { EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); // Now, rename the profile. - const string16 new_profile_name = ASCIIToUTF16("New profile"); + const string16 new_profile_name = L"New profile"; ASSERT_NE(second_profile_name_, new_profile_name); profile_info_cache_->SetNameOfProfileAtIndex( profile_info_cache_->GetIndexOfProfileWithPath(second_dest_path_), diff --git a/chrome/browser/profiles/profile_shortcut_manager_win.cc b/chrome/browser/profiles/profile_shortcut_manager_win.cc index f20180e..5afb8da 100644 --- a/chrome/browser/profiles/profile_shortcut_manager_win.cc +++ b/chrome/browser/profiles/profile_shortcut_manager_win.cc @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/profiles/profile_shortcut_manager.h" +#include "chrome/browser/profiles/profile_shortcut_manager_win.h" -#include <map> +#include <string> +#include <vector> #include "base/bind.h" -#include "base/command_line.h" #include "base/file_util.h" #include "base/path_service.h" #include "base/string16.h" @@ -16,22 +16,16 @@ #include "base/win/shortcut.h" #include "chrome/browser/app_icon_win.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile_info_cache_observer.h" #include "chrome/browser/profiles/profile_info_util.h" #include "chrome/browser/profiles/profile_manager.h" -#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/pref_names.h" -#include "chrome/installer/util/auto_launch_util.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/product.h" #include "chrome/installer/util/shell_util.h" #include "content/public/browser/browser_thread.h" -#include "grit/generated_resources.h" #include "skia/ext/image_operations.h" #include "skia/ext/platform_canvas.h" -#include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/icon_util.h" #include "ui/gfx/image/image.h" @@ -218,7 +212,8 @@ void CreateOrUpdateDesktopShortcutsForProfile(const FilePath& profile_path, ListDesktopShortcutsWithCommandLine(chrome_exe, command_line, &shortcuts); if (create && shortcuts.empty()) { const string16 shortcut_name = - ProfileShortcutManager::GetShortcutNameForProfile(profile_name); + profiles::internal::GetShortcutFilenameForProfile(profile_name, + distribution); shortcuts.push_back(FilePath(shortcut_name)); operation = ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS; } @@ -262,36 +257,22 @@ void DeleteDesktopShortcutsAndIconFile(const FilePath& profile_path, } // namespace -class ProfileShortcutManagerWin : public ProfileShortcutManager, - public ProfileInfoCacheObserver { - public: - explicit ProfileShortcutManagerWin(ProfileManager* manager); - virtual ~ProfileShortcutManagerWin(); - - virtual void CreateProfileShortcut(const FilePath& profile_path) OVERRIDE; - - // ProfileInfoCacheObserver: - virtual void OnProfileAdded(const FilePath& profile_path) OVERRIDE; - virtual void OnProfileWillBeRemoved(const FilePath& profile_path) OVERRIDE; - virtual void OnProfileWasRemoved(const FilePath& profile_path, - const string16& profile_name) OVERRIDE; - virtual void OnProfileNameChanged(const FilePath& profile_path, - const string16& old_profile_name) OVERRIDE; - virtual void OnProfileAvatarChanged(const FilePath& profile_path) OVERRIDE; - - private: - void StartProfileShortcutNameChange(const FilePath& profile_path, - const string16& old_profile_name); - // Gives the profile path of an alternate profile than |profile_path|. - // Must only be called when the number profiles is 2. - FilePath GetOtherProfilePath(const FilePath& profile_path); - void UpdateShortcutForProfileAtPath(const FilePath& profile_path, - bool create_always); - - ProfileManager* profile_manager_; - - DISALLOW_COPY_AND_ASSIGN(ProfileShortcutManagerWin); -}; +namespace profiles { +namespace internal { + +string16 GetShortcutFilenameForProfile(const string16& profile_name, + BrowserDistribution* distribution) { + string16 shortcut_name; + if (!profile_name.empty()) { + shortcut_name.append(profile_name); + shortcut_name.append(L" - "); + } + shortcut_name.append(distribution->GetAppShortCutName()); + return shortcut_name + installer::kLnkExt; +} + +} // namespace internal +} // namespace profiles // static bool ProfileShortcutManager::IsFeatureEnabled() { @@ -304,19 +285,6 @@ ProfileShortcutManager* ProfileShortcutManager::Create( return new ProfileShortcutManagerWin(manager); } -// static -string16 ProfileShortcutManager::GetShortcutNameForProfile( - const string16& profile_name) { - string16 shortcut_name; - if (!profile_name.empty()) { - shortcut_name.append(profile_name); - shortcut_name.append(L" - "); - } - BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); - shortcut_name.append(distribution->GetAppShortCutName()); - return shortcut_name + installer::kLnkExt; -} - ProfileShortcutManagerWin::ProfileShortcutManagerWin(ProfileManager* manager) : profile_manager_(manager) { profile_manager_->GetProfileInfoCache().AddObserver(this); @@ -328,16 +296,16 @@ ProfileShortcutManagerWin::~ProfileShortcutManagerWin() { void ProfileShortcutManagerWin::CreateProfileShortcut( const FilePath& profile_path) { - UpdateShortcutForProfileAtPath(profile_path, true); + UpdateShortcutsForProfileAtPath(profile_path, true); } void ProfileShortcutManagerWin::OnProfileAdded(const FilePath& profile_path) { const size_t profile_count = profile_manager_->GetProfileInfoCache().GetNumberOfProfiles(); if (profile_count == 1) { - UpdateShortcutForProfileAtPath(profile_path, true); + UpdateShortcutsForProfileAtPath(profile_path, true); } else if (profile_count == 2) { - UpdateShortcutForProfileAtPath(GetOtherProfilePath(profile_path), false); + UpdateShortcutsForProfileAtPath(GetOtherProfilePath(profile_path), false); } } @@ -352,7 +320,7 @@ void ProfileShortcutManagerWin::OnProfileWasRemoved( // If there is only one profile remaining, remove the badging information // from an existing shortcut. if (cache.GetNumberOfProfiles() == 1) - UpdateShortcutForProfileAtPath(cache.GetPathOfProfileAtIndex(0), false); + UpdateShortcutsForProfileAtPath(cache.GetPathOfProfileAtIndex(0), false); const FilePath icon_path = profile_path.AppendASCII(kProfileIconFileName); BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, @@ -363,12 +331,12 @@ void ProfileShortcutManagerWin::OnProfileWasRemoved( void ProfileShortcutManagerWin::OnProfileNameChanged( const FilePath& profile_path, const string16& old_profile_name) { - UpdateShortcutForProfileAtPath(profile_path, false); + UpdateShortcutsForProfileAtPath(profile_path, false); } void ProfileShortcutManagerWin::OnProfileAvatarChanged( const FilePath& profile_path) { - UpdateShortcutForProfileAtPath(profile_path, false); + UpdateShortcutsForProfileAtPath(profile_path, false); } void ProfileShortcutManagerWin::StartProfileShortcutNameChange( @@ -383,8 +351,13 @@ void ProfileShortcutManagerWin::StartProfileShortcutNameChange( if (cache.GetNumberOfProfiles() != 1) new_profile_name = cache.GetNameOfProfileAtIndex(profile_index); - string16 old_shortcut_file(GetShortcutNameForProfile(old_profile_name)); - string16 new_shortcut_file(GetShortcutNameForProfile(new_profile_name)); + BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); + const string16 old_shortcut_file = + profiles::internal::GetShortcutFilenameForProfile(old_profile_name, + distribution); + const string16 new_shortcut_file = + profiles::internal::GetShortcutFilenameForProfile(new_profile_name, + distribution); BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, base::Bind(&RenameChromeDesktopShortcutForProfile, @@ -404,7 +377,7 @@ FilePath ProfileShortcutManagerWin::GetOtherProfilePath( GetPathOfProfileAtIndex(other_profile_index); } -void ProfileShortcutManagerWin::UpdateShortcutForProfileAtPath( +void ProfileShortcutManagerWin::UpdateShortcutsForProfileAtPath( const FilePath& profile_path, bool create_always) { ProfileInfoCache* cache = &profile_manager_->GetProfileInfoCache(); diff --git a/chrome/browser/profiles/profile_shortcut_manager_win.h b/chrome/browser/profiles/profile_shortcut_manager_win.h new file mode 100644 index 0000000..36d747b --- /dev/null +++ b/chrome/browser/profiles/profile_shortcut_manager_win.h @@ -0,0 +1,57 @@ +// Copyright (c) 2012 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. + +#ifndef CHROME_BROWSER_PROFILES_PROFILE_SHORTCUT_MANAGER_WIN_H_ +#define CHROME_BROWSER_PROFILES_PROFILE_SHORTCUT_MANAGER_WIN_H_ + +#include "chrome/browser/profiles/profile_shortcut_manager.h" + +class BrowserDistribution; + +// Internal free-standing functions that are exported here for testing. +namespace profiles { +namespace internal { + +// Returns the default shortcut filename for the given profile name, +// given |distribution|. Returns a filename appropriate for a +// single-user installation if |profile_name| is empty. +string16 GetShortcutFilenameForProfile(const string16& profile_name, + BrowserDistribution* distribution); + +} // namespace internal +} // namespace profiles + +class ProfileShortcutManagerWin : public ProfileShortcutManager, + public ProfileInfoCacheObserver { + public: + explicit ProfileShortcutManagerWin(ProfileManager* manager); + virtual ~ProfileShortcutManagerWin(); + + // ProfileShortcutManager implementation: + virtual void CreateProfileShortcut(const FilePath& profile_path) OVERRIDE; + + // ProfileInfoCacheObserver implementation: + virtual void OnProfileAdded(const FilePath& profile_path) OVERRIDE; + virtual void OnProfileWillBeRemoved(const FilePath& profile_path) OVERRIDE; + virtual void OnProfileWasRemoved(const FilePath& profile_path, + const string16& profile_name) OVERRIDE; + virtual void OnProfileNameChanged(const FilePath& profile_path, + const string16& old_profile_name) OVERRIDE; + virtual void OnProfileAvatarChanged(const FilePath& profile_path) OVERRIDE; + + private: + void StartProfileShortcutNameChange(const FilePath& profile_path, + const string16& old_profile_name); + // Gives the profile path of an alternate profile than |profile_path|. + // Must only be called when the number profiles is 2. + FilePath GetOtherProfilePath(const FilePath& profile_path); + void UpdateShortcutsForProfileAtPath(const FilePath& profile_path, + bool create_always); + + ProfileManager* profile_manager_; + + DISALLOW_COPY_AND_ASSIGN(ProfileShortcutManagerWin); +}; + +#endif // CHROME_BROWSER_PROFILES_PROFILE_SHORTCUT_MANAGER_WIN_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 455bdb2..a17e164 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1583,14 +1583,15 @@ 'browser/profiles/profile_manager.h', 'browser/profiles/profile_metrics.cc', 'browser/profiles/profile_metrics.h', - 'browser/profiles/profile_shortcut_manager.h', 'browser/profiles/profile_shortcut_manager.cc', + 'browser/profiles/profile_shortcut_manager.h', 'browser/profiles/profile_shortcut_manager_stub.cc', 'browser/profiles/profile_shortcut_manager_win.cc', - 'browser/profiles/refcounted_profile_keyed_service.h', + 'browser/profiles/profile_shortcut_manager_win.h', 'browser/profiles/refcounted_profile_keyed_service.cc', - 'browser/profiles/refcounted_profile_keyed_service_factory.h', + 'browser/profiles/refcounted_profile_keyed_service.h', 'browser/profiles/refcounted_profile_keyed_service_factory.cc', + 'browser/profiles/refcounted_profile_keyed_service_factory.h', 'browser/profiles/storage_partition_descriptor.h', 'browser/protector/base_prefs_change.cc', 'browser/protector/base_prefs_change.h', |