diff options
author | dpolukhin@chromium.org <dpolukhin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-24 05:37:04 +0000 |
---|---|---|
committer | dpolukhin@chromium.org <dpolukhin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-24 05:37:04 +0000 |
commit | a10db145b555dc0c22338964df5cd2d089faa976 (patch) | |
tree | cd03266ec10d88e2c2c8b82cfd01cedd773777db | |
parent | 6c1478d9524152a088fde1e49e19f24d1942a2a2 (diff) | |
download | chromium_src-a10db145b555dc0c22338964df5cd2d089faa976.zip chromium_src-a10db145b555dc0c22338964df5cd2d089faa976.tar.gz chromium_src-a10db145b555dc0c22338964df5cd2d089faa976.tar.bz2 |
Set OEM apps folder name from customization manifest
BUG=351567
TEST=unit_tests
R=nkostylev@chromium.org, stevenjb@chromium.org
Review URL: https://codereview.chromium.org/206673006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258879 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 105 insertions, 22 deletions
diff --git a/chrome/browser/chromeos/customization_document.cc b/chrome/browser/chromeos/customization_document.cc index e0248d9..99d7d82 100644 --- a/chrome/browser/chromeos/customization_document.cc +++ b/chrome/browser/chromeos/customization_document.cc @@ -25,6 +25,8 @@ #include "chrome/browser/extensions/external_loader.h" #include "chrome/browser/extensions/external_provider_impl.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/app_list/app_list_syncable_service.h" +#include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" #include "chrome/common/extensions/extension_constants.h" #include "chromeos/network/network_state.h" #include "chromeos/network/network_state_handler.h" @@ -53,6 +55,8 @@ const char kSetupContentAttr[] = "setup_content"; const char kEulaPageAttr[] = "eula_page"; const char kDefaultWallpaperAttr[] = "default_wallpaper"; const char kDefaultAppsAttr[] = "default_apps"; +const char kLocalizedContent[] = "localized_content"; +const char kDefaultAppsFolderName[] = "default_apps_folder_name"; const char kAcceptedManifestVersion[] = "1.0"; @@ -93,6 +97,32 @@ void LogManifestLoadResult(HistogramServicesCustomizationLoadResult result) { HISTOGRAM_LOAD_RESULT_MAX_VALUE); } +std::string GetLocaleSpecificStringImpl( + const base::DictionaryValue* root, + const std::string& locale, + const std::string& dictionary_name, + const std::string& entry_name) { + const base::DictionaryValue* dictionary_content = NULL; + if (!root || !root->GetDictionary(dictionary_name, &dictionary_content)) + return std::string(); + + const base::DictionaryValue* locale_dictionary = NULL; + if (dictionary_content->GetDictionary(locale, &locale_dictionary)) { + std::string result; + if (locale_dictionary->GetString(entry_name, &result)) + return result; + } + + const base::DictionaryValue* default_dictionary = NULL; + if (dictionary_content->GetDictionary(kDefaultAttr, &default_dictionary)) { + std::string result; + if (default_dictionary->GetString(entry_name, &result)) + return result; + } + + return std::string(); +} + } // anonymous namespace namespace chromeos { @@ -191,26 +221,8 @@ std::string CustomizationDocument::GetLocaleSpecificString( const std::string& locale, const std::string& dictionary_name, const std::string& entry_name) const { - base::DictionaryValue* dictionary_content = NULL; - if (!root_.get() || - !root_->GetDictionary(dictionary_name, &dictionary_content)) - return std::string(); - - base::DictionaryValue* locale_dictionary = NULL; - if (dictionary_content->GetDictionary(locale, &locale_dictionary)) { - std::string result; - if (locale_dictionary->GetString(entry_name, &result)) - return result; - } - - base::DictionaryValue* default_dictionary = NULL; - if (dictionary_content->GetDictionary(kDefaultAttr, &default_dictionary)) { - std::string result; - if (default_dictionary->GetString(entry_name, &result)) - return result; - } - - return std::string(); + return GetLocaleSpecificStringImpl( + root_.get(), locale, dictionary_name, entry_name); } // StartupCustomizationDocument implementation. -------------------------------- @@ -464,6 +476,7 @@ void ServicesCustomizationDocument::OnManifestLoaded() { UpdateCachedManifest((*it)->profile()); (*it)->SetCurrentApps( scoped_ptr<base::DictionaryValue>(prefs->DeepCopy())); + SetOemFolderName((*it)->profile(), *root_); } } } @@ -541,6 +554,14 @@ bool ServicesCustomizationDocument::GetDefaultApps( return true; } +std::string ServicesCustomizationDocument::GetOemAppsFolderName( + const std::string& locale) const { + if (!IsReady()) + return std::string(); + + return GetOemAppsFolderNameImpl(locale, *root_); +} + scoped_ptr<base::DictionaryValue> ServicesCustomizationDocument::GetDefaultAppsInProviderFormat( const base::DictionaryValue& root) { @@ -578,6 +599,7 @@ extensions::ExternalLoader* ServicesCustomizationDocument::CreateExternalLoader( if (IsReady()) { UpdateCachedManifest(profile); loader->SetCurrentApps(GetDefaultAppsInProviderFormat(*root_)); + SetOemFolderName(profile, *root_); } else { const base::DictionaryValue* root = profile->GetPrefs()->GetDictionary(kServicesCustomizationKey); @@ -585,6 +607,7 @@ extensions::ExternalLoader* ServicesCustomizationDocument::CreateExternalLoader( if (root && root->GetString(kVersionAttr, &version)) { // If version exists, profile has cached version of customization. loader->SetCurrentApps(GetDefaultAppsInProviderFormat(*root)); + SetOemFolderName(profile, *root); } else { // StartFetching will be called from ServicesCustomizationExternalLoader // when StartLoading is called. We can't initiate manifest fetch here @@ -600,4 +623,28 @@ void ServicesCustomizationDocument::OnCustomizationNotFound() { LoadManifestFromString(kEmptyServicesCustomizationManifest); } +void ServicesCustomizationDocument::SetOemFolderName( + Profile* profile, + const base::DictionaryValue& root) { + app_list::AppListSyncableService* service = + app_list::AppListSyncableServiceFactory::GetForProfile(profile); + if (!service) { + LOG(WARNING) << "AppListSyncableService is not ready for setting OEM " + "folder name"; + return; + } + + std::string locale = g_browser_process->GetApplicationLocale(); + std::string name = GetOemAppsFolderNameImpl(locale, root); + if (!name.empty()) + service->SetOemFolderName(name); +} + +std::string ServicesCustomizationDocument::GetOemAppsFolderNameImpl( + const std::string& locale, + const base::DictionaryValue& root) const { + return GetLocaleSpecificStringImpl( + &root, locale, kLocalizedContent, kDefaultAppsFolderName); +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/customization_document.h b/chrome/browser/chromeos/customization_document.h index e14f633..95885fc 100644 --- a/chrome/browser/chromeos/customization_document.h +++ b/chrome/browser/chromeos/customization_document.h @@ -169,6 +169,9 @@ class ServicesCustomizationDocument : public CustomizationDocument, // Cache of OEM default apps stored in profile preferences. extensions::ExternalLoader* CreateExternalLoader(Profile* profile); + // Returns the name of the folder for OEM apps for given |locale|. + std::string GetOemAppsFolderName(const std::string& locale) const; + // Set delay between network checking for testing. void SetZeroNetworkDelayForTesting() { network_delay_ = base::TimeDelta(); @@ -224,6 +227,14 @@ class ServicesCustomizationDocument : public CustomizationDocument, // Customization document not found for give ID. void OnCustomizationNotFound(); + // Set OEM apps folder name for AppListSyncableService for |profile|. + void SetOemFolderName(Profile* profile, const base::DictionaryValue& root); + + // Returns the name of the folder for OEM apps for given |locale|. + std::string GetOemAppsFolderNameImpl( + const std::string& locale, + const base::DictionaryValue& root) const; + // Services customization manifest URL. GURL url_; diff --git a/chrome/browser/chromeos/customization_document_unittest.cc b/chrome/browser/chromeos/customization_document_unittest.cc index 1ae068e..130462f 100644 --- a/chrome/browser/chromeos/customization_document_unittest.cc +++ b/chrome/browser/chromeos/customization_document_unittest.cc @@ -14,6 +14,8 @@ #include "chrome/browser/prefs/browser_prefs.h" #include "chrome/browser/prefs/pref_service_mock_factory.h" #include "chrome/browser/prefs/pref_service_syncable.h" +#include "chrome/browser/ui/app_list/app_list_syncable_service.h" +#include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" #include "chromeos/dbus/dbus_thread_manager.h" @@ -79,7 +81,18 @@ const char kGoodServicesManifest[] = " \"default_apps\": [\n" " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n" " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\"\n" - " ]\n" + " ],\n" + " \"localized_content\": {\n" + " \"en-US\": {\n" + " \"default_apps_folder_name\": \"EN-US OEM Name\"\n" + " },\n" + " \"en\": {\n" + " \"default_apps_folder_name\": \"EN OEM Name\"\n" + " },\n" + " \"default\": {\n" + " \"default_apps_folder_name\": \"Default OEM Name\"\n" + " }\n" + " }\n" "}"; const char kDummyCustomizationID[] = "test-dummy"; @@ -317,6 +330,10 @@ TEST_F(ServicesCustomizationDocumentTest, Basic) { EXPECT_EQ(default_apps[0], "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); EXPECT_EQ(default_apps[1], "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); + + EXPECT_EQ(doc->GetOemAppsFolderName("en-US"), "EN-US OEM Name"); + EXPECT_EQ(doc->GetOemAppsFolderName("en"), "EN OEM Name"); + EXPECT_EQ(doc->GetOemAppsFolderName("ru"), "Default OEM Name"); } TEST_F(ServicesCustomizationDocumentTest, NoCustomizationIdInVpd) { @@ -400,6 +417,11 @@ TEST_F(ServicesCustomizationDocumentTest, DefaultApps) { RunUntilIdle(); EXPECT_TRUE(doc->IsReady()); + + app_list::AppListSyncableService* service = + app_list::AppListSyncableServiceFactory::GetForProfile(profile.get()); + ASSERT_TRUE(service); + EXPECT_EQ(service->GetOemFolderNameForTest(), "EN OEM Name"); } TEST_F(ServicesCustomizationDocumentTest, CustomizationManifestNotFound) { diff --git a/chrome/browser/ui/app_list/app_list_syncable_service.h b/chrome/browser/ui/app_list/app_list_syncable_service.h index 949b49f..5c9993b 100644 --- a/chrome/browser/ui/app_list/app_list_syncable_service.h +++ b/chrome/browser/ui/app_list/app_list_syncable_service.h @@ -79,7 +79,10 @@ class AppListSyncableService : public syncer::SyncableService, Profile* profile() { return profile_; } AppListModel* model() { return model_.get(); } - size_t GetNumSyncItemsForTest() { return sync_items_.size(); } + size_t GetNumSyncItemsForTest() const { return sync_items_.size(); } + const std::string& GetOemFolderNameForTest() const { + return oem_folder_name_; + } // syncer::SyncableService virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |