OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/chromeos/customization_document.h" | 5 #include "chrome/browser/chromeos/customization_document.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/prefs/pref_registry_simple.h" | 15 #include "base/prefs/pref_registry_simple.h" |
16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
17 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
23 #include "chrome/browser/chromeos/login/wizard_controller.h" | 23 #include "chrome/browser/chromeos/login/wizard_controller.h" |
24 #include "chrome/browser/chromeos/net/delay_network_call.h" | 24 #include "chrome/browser/chromeos/net/delay_network_call.h" |
25 #include "chrome/browser/extensions/external_loader.h" | 25 #include "chrome/browser/extensions/external_loader.h" |
26 #include "chrome/browser/extensions/external_provider_impl.h" | 26 #include "chrome/browser/extensions/external_provider_impl.h" |
27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
| 29 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
28 #include "chrome/common/extensions/extension_constants.h" | 30 #include "chrome/common/extensions/extension_constants.h" |
29 #include "chromeos/network/network_state.h" | 31 #include "chromeos/network/network_state.h" |
30 #include "chromeos/network/network_state_handler.h" | 32 #include "chromeos/network/network_state_handler.h" |
31 #include "chromeos/system/statistics_provider.h" | 33 #include "chromeos/system/statistics_provider.h" |
32 #include "components/user_prefs/pref_registry_syncable.h" | 34 #include "components/user_prefs/pref_registry_syncable.h" |
33 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
34 #include "net/base/load_flags.h" | 36 #include "net/base/load_flags.h" |
35 #include "net/http/http_response_headers.h" | 37 #include "net/http/http_response_headers.h" |
36 #include "net/http/http_status_code.h" | 38 #include "net/http/http_status_code.h" |
37 #include "net/url_request/url_fetcher.h" | 39 #include "net/url_request/url_fetcher.h" |
38 | 40 |
39 using content::BrowserThread; | 41 using content::BrowserThread; |
40 | 42 |
41 // Manifest attributes names. | 43 // Manifest attributes names. |
42 | 44 |
43 namespace { | 45 namespace { |
44 | 46 |
45 const char kVersionAttr[] = "version"; | 47 const char kVersionAttr[] = "version"; |
46 const char kDefaultAttr[] = "default"; | 48 const char kDefaultAttr[] = "default"; |
47 const char kInitialLocaleAttr[] = "initial_locale"; | 49 const char kInitialLocaleAttr[] = "initial_locale"; |
48 const char kInitialTimezoneAttr[] = "initial_timezone"; | 50 const char kInitialTimezoneAttr[] = "initial_timezone"; |
49 const char kKeyboardLayoutAttr[] = "keyboard_layout"; | 51 const char kKeyboardLayoutAttr[] = "keyboard_layout"; |
50 const char kHwidMapAttr[] = "hwid_map"; | 52 const char kHwidMapAttr[] = "hwid_map"; |
51 const char kHwidMaskAttr[] = "hwid_mask"; | 53 const char kHwidMaskAttr[] = "hwid_mask"; |
52 const char kSetupContentAttr[] = "setup_content"; | 54 const char kSetupContentAttr[] = "setup_content"; |
53 const char kEulaPageAttr[] = "eula_page"; | 55 const char kEulaPageAttr[] = "eula_page"; |
54 const char kDefaultWallpaperAttr[] = "default_wallpaper"; | 56 const char kDefaultWallpaperAttr[] = "default_wallpaper"; |
55 const char kDefaultAppsAttr[] = "default_apps"; | 57 const char kDefaultAppsAttr[] = "default_apps"; |
| 58 const char kLocalizedContent[] = "localized_content"; |
| 59 const char kDefaultAppsFolderName[] = "default_apps_folder_name"; |
56 | 60 |
57 const char kAcceptedManifestVersion[] = "1.0"; | 61 const char kAcceptedManifestVersion[] = "1.0"; |
58 | 62 |
59 // Path to OEM partner startup customization manifest. | 63 // Path to OEM partner startup customization manifest. |
60 const char kStartupCustomizationManifestPath[] = | 64 const char kStartupCustomizationManifestPath[] = |
61 "/opt/oem/etc/startup_manifest.json"; | 65 "/opt/oem/etc/startup_manifest.json"; |
62 | 66 |
63 // Name of local state option that tracks if services customization has been | 67 // Name of local state option that tracks if services customization has been |
64 // applied. | 68 // applied. |
65 const char kServicesCustomizationAppliedPref[] = "ServicesCustomizationApplied"; | 69 const char kServicesCustomizationAppliedPref[] = "ServicesCustomizationApplied"; |
(...skipping 20 matching lines...) Expand all Loading... |
86 HISTOGRAM_LOAD_RESULT_RETRIES_FAIL = 3, | 90 HISTOGRAM_LOAD_RESULT_RETRIES_FAIL = 3, |
87 HISTOGRAM_LOAD_RESULT_MAX_VALUE = 4 | 91 HISTOGRAM_LOAD_RESULT_MAX_VALUE = 4 |
88 }; | 92 }; |
89 | 93 |
90 void LogManifestLoadResult(HistogramServicesCustomizationLoadResult result) { | 94 void LogManifestLoadResult(HistogramServicesCustomizationLoadResult result) { |
91 UMA_HISTOGRAM_ENUMERATION("ServicesCustomization.LoadResult", | 95 UMA_HISTOGRAM_ENUMERATION("ServicesCustomization.LoadResult", |
92 result, | 96 result, |
93 HISTOGRAM_LOAD_RESULT_MAX_VALUE); | 97 HISTOGRAM_LOAD_RESULT_MAX_VALUE); |
94 } | 98 } |
95 | 99 |
| 100 std::string GetLocaleSpecificStringImpl( |
| 101 const base::DictionaryValue* root, |
| 102 const std::string& locale, |
| 103 const std::string& dictionary_name, |
| 104 const std::string& entry_name) { |
| 105 const base::DictionaryValue* dictionary_content = NULL; |
| 106 if (!root || !root->GetDictionary(dictionary_name, &dictionary_content)) |
| 107 return std::string(); |
| 108 |
| 109 const base::DictionaryValue* locale_dictionary = NULL; |
| 110 if (dictionary_content->GetDictionary(locale, &locale_dictionary)) { |
| 111 std::string result; |
| 112 if (locale_dictionary->GetString(entry_name, &result)) |
| 113 return result; |
| 114 } |
| 115 |
| 116 const base::DictionaryValue* default_dictionary = NULL; |
| 117 if (dictionary_content->GetDictionary(kDefaultAttr, &default_dictionary)) { |
| 118 std::string result; |
| 119 if (default_dictionary->GetString(entry_name, &result)) |
| 120 return result; |
| 121 } |
| 122 |
| 123 return std::string(); |
| 124 } |
| 125 |
96 } // anonymous namespace | 126 } // anonymous namespace |
97 | 127 |
98 namespace chromeos { | 128 namespace chromeos { |
99 | 129 |
100 // Template URL where to fetch OEM services customization manifest from. | 130 // Template URL where to fetch OEM services customization manifest from. |
101 const char ServicesCustomizationDocument::kManifestUrl[] = | 131 const char ServicesCustomizationDocument::kManifestUrl[] = |
102 "https://ssl.gstatic.com/chrome/chromeos-customization/%s.json"; | 132 "https://ssl.gstatic.com/chrome/chromeos-customization/%s.json"; |
103 | 133 |
104 // A custom extensions::ExternalLoader that the ServicesCustomizationDocument | 134 // A custom extensions::ExternalLoader that the ServicesCustomizationDocument |
105 // creates and uses to publish OEM default apps to the extensions system. | 135 // creates and uses to publish OEM default apps to the extensions system. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 LOG(ERROR) << "Wrong customization manifest version"; | 214 LOG(ERROR) << "Wrong customization manifest version"; |
185 root_.reset(NULL); | 215 root_.reset(NULL); |
186 } | 216 } |
187 return false; | 217 return false; |
188 } | 218 } |
189 | 219 |
190 std::string CustomizationDocument::GetLocaleSpecificString( | 220 std::string CustomizationDocument::GetLocaleSpecificString( |
191 const std::string& locale, | 221 const std::string& locale, |
192 const std::string& dictionary_name, | 222 const std::string& dictionary_name, |
193 const std::string& entry_name) const { | 223 const std::string& entry_name) const { |
194 base::DictionaryValue* dictionary_content = NULL; | 224 return GetLocaleSpecificStringImpl( |
195 if (!root_.get() || | 225 root_.get(), locale, dictionary_name, entry_name); |
196 !root_->GetDictionary(dictionary_name, &dictionary_content)) | |
197 return std::string(); | |
198 | |
199 base::DictionaryValue* locale_dictionary = NULL; | |
200 if (dictionary_content->GetDictionary(locale, &locale_dictionary)) { | |
201 std::string result; | |
202 if (locale_dictionary->GetString(entry_name, &result)) | |
203 return result; | |
204 } | |
205 | |
206 base::DictionaryValue* default_dictionary = NULL; | |
207 if (dictionary_content->GetDictionary(kDefaultAttr, &default_dictionary)) { | |
208 std::string result; | |
209 if (default_dictionary->GetString(entry_name, &result)) | |
210 return result; | |
211 } | |
212 | |
213 return std::string(); | |
214 } | 226 } |
215 | 227 |
216 // StartupCustomizationDocument implementation. -------------------------------- | 228 // StartupCustomizationDocument implementation. -------------------------------- |
217 | 229 |
218 StartupCustomizationDocument::StartupCustomizationDocument() | 230 StartupCustomizationDocument::StartupCustomizationDocument() |
219 : CustomizationDocument(kAcceptedManifestVersion) { | 231 : CustomizationDocument(kAcceptedManifestVersion) { |
220 { | 232 { |
221 // Loading manifest causes us to do blocking IO on UI thread. | 233 // Loading manifest causes us to do blocking IO on UI thread. |
222 // Temporarily allow it until we fix http://crosbug.com/11103 | 234 // Temporarily allow it until we fix http://crosbug.com/11103 |
223 base::ThreadRestrictions::ScopedAllowIO allow_io; | 235 base::ThreadRestrictions::ScopedAllowIO allow_io; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 ApplyOOBECustomization(); | 469 ApplyOOBECustomization(); |
458 | 470 |
459 scoped_ptr<base::DictionaryValue> prefs = | 471 scoped_ptr<base::DictionaryValue> prefs = |
460 GetDefaultAppsInProviderFormat(*root_); | 472 GetDefaultAppsInProviderFormat(*root_); |
461 for (ExternalLoaders::iterator it = external_loaders_.begin(); | 473 for (ExternalLoaders::iterator it = external_loaders_.begin(); |
462 it != external_loaders_.end(); ++it) { | 474 it != external_loaders_.end(); ++it) { |
463 if (*it) { | 475 if (*it) { |
464 UpdateCachedManifest((*it)->profile()); | 476 UpdateCachedManifest((*it)->profile()); |
465 (*it)->SetCurrentApps( | 477 (*it)->SetCurrentApps( |
466 scoped_ptr<base::DictionaryValue>(prefs->DeepCopy())); | 478 scoped_ptr<base::DictionaryValue>(prefs->DeepCopy())); |
| 479 SetOemFolderName((*it)->profile(), *root_); |
467 } | 480 } |
468 } | 481 } |
469 } | 482 } |
470 | 483 |
471 void ServicesCustomizationDocument::OnURLFetchComplete( | 484 void ServicesCustomizationDocument::OnURLFetchComplete( |
472 const net::URLFetcher* source) { | 485 const net::URLFetcher* source) { |
473 std::string mime_type; | 486 std::string mime_type; |
474 std::string data; | 487 std::string data; |
475 if (source->GetStatus().is_success() && | 488 if (source->GetStatus().is_success() && |
476 source->GetResponseCode() == net::HTTP_OK && | 489 source->GetResponseCode() == net::HTTP_OK && |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 ids->push_back(app_id); | 547 ids->push_back(app_id); |
535 } else { | 548 } else { |
536 LOG(ERROR) << "Wrong format of default application list"; | 549 LOG(ERROR) << "Wrong format of default application list"; |
537 return false; | 550 return false; |
538 } | 551 } |
539 } | 552 } |
540 | 553 |
541 return true; | 554 return true; |
542 } | 555 } |
543 | 556 |
| 557 std::string ServicesCustomizationDocument::GetOemAppsFolderName( |
| 558 const std::string& locale) const { |
| 559 if (!IsReady()) |
| 560 return std::string(); |
| 561 |
| 562 return GetOemAppsFolderNameImpl(locale, *root_); |
| 563 } |
| 564 |
544 scoped_ptr<base::DictionaryValue> | 565 scoped_ptr<base::DictionaryValue> |
545 ServicesCustomizationDocument::GetDefaultAppsInProviderFormat( | 566 ServicesCustomizationDocument::GetDefaultAppsInProviderFormat( |
546 const base::DictionaryValue& root) { | 567 const base::DictionaryValue& root) { |
547 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 568 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
548 const base::ListValue* apps_list = NULL; | 569 const base::ListValue* apps_list = NULL; |
549 if (root.GetList(kDefaultAppsAttr, &apps_list)) { | 570 if (root.GetList(kDefaultAppsAttr, &apps_list)) { |
550 for (size_t i = 0; i < apps_list->GetSize(); ++i) { | 571 for (size_t i = 0; i < apps_list->GetSize(); ++i) { |
551 std::string app_id; | 572 std::string app_id; |
552 if (apps_list->GetString(i, &app_id)) { | 573 if (apps_list->GetString(i, &app_id)) { |
553 base::DictionaryValue* entry = new base::DictionaryValue; | 574 base::DictionaryValue* entry = new base::DictionaryValue; |
(...skipping 17 matching lines...) Expand all Loading... |
571 | 592 |
572 extensions::ExternalLoader* ServicesCustomizationDocument::CreateExternalLoader( | 593 extensions::ExternalLoader* ServicesCustomizationDocument::CreateExternalLoader( |
573 Profile* profile) { | 594 Profile* profile) { |
574 ServicesCustomizationExternalLoader* loader = | 595 ServicesCustomizationExternalLoader* loader = |
575 new ServicesCustomizationExternalLoader(profile); | 596 new ServicesCustomizationExternalLoader(profile); |
576 external_loaders_.push_back(loader->AsWeakPtr()); | 597 external_loaders_.push_back(loader->AsWeakPtr()); |
577 | 598 |
578 if (IsReady()) { | 599 if (IsReady()) { |
579 UpdateCachedManifest(profile); | 600 UpdateCachedManifest(profile); |
580 loader->SetCurrentApps(GetDefaultAppsInProviderFormat(*root_)); | 601 loader->SetCurrentApps(GetDefaultAppsInProviderFormat(*root_)); |
| 602 SetOemFolderName(profile, *root_); |
581 } else { | 603 } else { |
582 const base::DictionaryValue* root = | 604 const base::DictionaryValue* root = |
583 profile->GetPrefs()->GetDictionary(kServicesCustomizationKey); | 605 profile->GetPrefs()->GetDictionary(kServicesCustomizationKey); |
584 std::string version; | 606 std::string version; |
585 if (root && root->GetString(kVersionAttr, &version)) { | 607 if (root && root->GetString(kVersionAttr, &version)) { |
586 // If version exists, profile has cached version of customization. | 608 // If version exists, profile has cached version of customization. |
587 loader->SetCurrentApps(GetDefaultAppsInProviderFormat(*root)); | 609 loader->SetCurrentApps(GetDefaultAppsInProviderFormat(*root)); |
| 610 SetOemFolderName(profile, *root); |
588 } else { | 611 } else { |
589 // StartFetching will be called from ServicesCustomizationExternalLoader | 612 // StartFetching will be called from ServicesCustomizationExternalLoader |
590 // when StartLoading is called. We can't initiate manifest fetch here | 613 // when StartLoading is called. We can't initiate manifest fetch here |
591 // because caller may never call StartLoading for the provider. | 614 // because caller may never call StartLoading for the provider. |
592 } | 615 } |
593 } | 616 } |
594 | 617 |
595 return loader; | 618 return loader; |
596 } | 619 } |
597 | 620 |
598 void ServicesCustomizationDocument::OnCustomizationNotFound() { | 621 void ServicesCustomizationDocument::OnCustomizationNotFound() { |
599 LogManifestLoadResult(HISTOGRAM_LOAD_RESULT_FILE_NOT_FOUND); | 622 LogManifestLoadResult(HISTOGRAM_LOAD_RESULT_FILE_NOT_FOUND); |
600 LoadManifestFromString(kEmptyServicesCustomizationManifest); | 623 LoadManifestFromString(kEmptyServicesCustomizationManifest); |
601 } | 624 } |
602 | 625 |
| 626 void ServicesCustomizationDocument::SetOemFolderName( |
| 627 Profile* profile, |
| 628 const base::DictionaryValue& root) { |
| 629 app_list::AppListSyncableService* service = |
| 630 app_list::AppListSyncableServiceFactory::GetForProfile(profile); |
| 631 if (!service) { |
| 632 LOG(WARNING) << "AppListSyncableService is not ready for setting OEM " |
| 633 "folder name"; |
| 634 return; |
| 635 } |
| 636 |
| 637 std::string locale = g_browser_process->GetApplicationLocale(); |
| 638 std::string name = GetOemAppsFolderNameImpl(locale, root); |
| 639 if (!name.empty()) |
| 640 service->SetOemFolderName(name); |
| 641 } |
| 642 |
| 643 std::string ServicesCustomizationDocument::GetOemAppsFolderNameImpl( |
| 644 const std::string& locale, |
| 645 const base::DictionaryValue& root) const { |
| 646 return GetLocaleSpecificStringImpl( |
| 647 &root, locale, kLocalizedContent, kDefaultAppsFolderName); |
| 648 } |
| 649 |
603 } // namespace chromeos | 650 } // namespace chromeos |
OLD | NEW |