Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: chrome/browser/chromeos/login/apply_services_customization.cc

Issue 6377003: Read services customization manifest on FILE thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: vlog Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/login/apply_services_customization.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/login/apply_services_customization.h" 5 #include "chrome/browser/chromeos/login/apply_services_customization.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/browser_thread.h"
13 #include "chrome/browser/chromeos/cros/cros_library.h" 14 #include "chrome/browser/chromeos/cros/cros_library.h"
14 #include "chrome/browser/chromeos/cros/network_library.h" 15 #include "chrome/browser/chromeos/cros/network_library.h"
15 #include "chrome/browser/chromeos/customization_document.h" 16 #include "chrome/browser/chromeos/customization_document.h"
16 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
18 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
19 20
20 namespace { 21 namespace {
21 22
22 // URL where to fetch OEM services customization manifest from. 23 // URL where to fetch OEM services customization manifest from.
23 // TODO(denisromanov): Change this to real URL when it becomes available. 24 // TODO(denisromanov): Change this to real URL when it becomes available.
24 const char kServicesCustomizationManifestUrl[] = 25 const char kServicesCustomizationManifestUrl[] =
25 "file:///mnt/partner_partition/etc/chromeos/services_manifest.json"; 26 "file:///mnt/partner_partition/etc/chromeos/services_manifest.json";
26 27
27 // Name of local state option that tracks if services customization has been 28 // Name of local state option that tracks if services customization has been
28 // applied. 29 // applied.
29 const char kServicesCustomizationAppliedPref[] = "ServicesCustomizationApplied"; 30 const char kServicesCustomizationAppliedPref[] = "ServicesCustomizationApplied";
30 31
31 // Maximum number of retries to fetch file if network is not available. 32 // Maximum number of retries to fetch file if network is not available.
32 const int kMaxFetchRetries = 3; 33 const int kMaxFetchRetries = 3;
33 34
34 // Delay between file fetch retries if network is not available. 35 // Delay between file fetch retries if network is not available.
35 const int kRetriesDelayInSec = 2; 36 const int kRetriesDelayInSec = 2;
36 37
37 } // namespace 38 } // namespace
38 39
40 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::ApplyServicesCustomization);
41
39 namespace chromeos { 42 namespace chromeos {
40 43
41
42 // static 44 // static
43 void ApplyServicesCustomization::StartIfNeeded() { 45 void ApplyServicesCustomization::StartIfNeeded() {
44 if (!IsApplied()) { 46 if (!IsApplied()) {
45 ApplyServicesCustomization* object = 47 ApplyServicesCustomization* object =
46 new ApplyServicesCustomization(kServicesCustomizationManifestUrl); 48 new ApplyServicesCustomization(kServicesCustomizationManifestUrl);
47 if (!object->Init()) { 49 if (!object->Init()) {
48 delete object; 50 delete object;
49 } 51 }
50 // |object| will be deleted on download complete. 52 // |object| will be deleted on download complete.
51 } 53 }
(...skipping 20 matching lines...) Expand all
72 const std::string& url_str) : url_(url_str), num_retries_(0) { 74 const std::string& url_str) : url_(url_str), num_retries_(0) {
73 } 75 }
74 76
75 bool ApplyServicesCustomization::Init() { 77 bool ApplyServicesCustomization::Init() {
76 DCHECK(url_.is_valid()); 78 DCHECK(url_.is_valid());
77 if (!url_.is_valid()) { 79 if (!url_.is_valid()) {
78 return false; 80 return false;
79 } 81 }
80 82
81 if (url_.SchemeIsFile()) { 83 if (url_.SchemeIsFile()) {
82 std::string manifest; 84 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
83 if (file_util::ReadFileToString(FilePath(url_.path()), &manifest)) { 85 NewRunnableMethod(this,
84 Apply(manifest); 86 &ApplyServicesCustomization::ReadFileInBackground,
85 } else { 87 FilePath(url_.path())));
86 LOG(ERROR) << "Failed to load services customization manifest from: " 88 } else {
87 << url_.path(); 89 StartFileFetch();
88 }
89
90 return false;
91 } 90 }
92 91
93 StartFileFetch();
94 return true; 92 return true;
95 } 93 }
96 94
97 void ApplyServicesCustomization::StartFileFetch() { 95 void ApplyServicesCustomization::StartFileFetch() {
98 url_fetcher_.reset(new URLFetcher(url_, URLFetcher::GET, this)); 96 url_fetcher_.reset(new URLFetcher(url_, URLFetcher::GET, this));
99 url_fetcher_->set_request_context( 97 url_fetcher_->set_request_context(
100 ProfileManager::GetDefaultProfile()->GetRequestContext()); 98 ProfileManager::GetDefaultProfile()->GetRequestContext());
101 url_fetcher_->Start(); 99 url_fetcher_->Start();
102 } 100 }
103 101
(...skipping 14 matching lines...) Expand all
118 this, &ApplyServicesCustomization::StartFileFetch); 116 this, &ApplyServicesCustomization::StartFileFetch);
119 return; 117 return;
120 } 118 }
121 LOG(ERROR) << "URL fetch for services customization failed:" 119 LOG(ERROR) << "URL fetch for services customization failed:"
122 << " response code = " << response_code 120 << " response code = " << response_code
123 << " URL = " << url.spec(); 121 << " URL = " << url.spec();
124 } 122 }
125 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 123 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
126 } 124 }
127 125
126 void ApplyServicesCustomization::ReadFileInBackground(const FilePath& file) {
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
128
129 std::string manifest;
130 if (file_util::ReadFileToString(file, &manifest)) {
131 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
132 NewRunnableMethod(
133 this, &ApplyServicesCustomization::ApplyAndDelete, manifest));
134 } else {
135 VLOG(1) << "Failed to load services customization manifest from: "
136 << file.value();
137 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
138 }
139 }
140
141 void ApplyServicesCustomization::ApplyAndDelete(const std::string& manifest) {
142 Apply(manifest);
143 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
144 }
145
128 void ApplyServicesCustomization::Apply(const std::string& manifest) { 146 void ApplyServicesCustomization::Apply(const std::string& manifest) {
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
148
129 chromeos::ServicesCustomizationDocument customization; 149 chromeos::ServicesCustomizationDocument customization;
130 if (!customization.LoadManifestFromString(manifest)) { 150 if (!customization.LoadManifestFromString(manifest)) {
131 LOG(ERROR) << "Failed to partner parse services customizations manifest"; 151 LOG(ERROR) << "Failed to partner parse services customizations manifest";
132 return; 152 return;
133 } 153 }
134 154
135 VLOG(1) << "Partner services customizations manifest loaded successfully"; 155 VLOG(1) << "Partner services customizations manifest loaded successfully";
136 if (!customization.initial_start_page_url().empty()) { 156 if (!customization.initial_start_page_url().empty()) {
137 // Append partner's start page url to command line so it gets opened 157 // Append partner's start page url to command line so it gets opened
138 // on browser startup. 158 // on browser startup.
139 CommandLine::ForCurrentProcess()->AppendArg( 159 CommandLine::ForCurrentProcess()->AppendArg(
140 customization.initial_start_page_url()); 160 customization.initial_start_page_url());
141 VLOG(1) << "initial_start_page_url: " 161 VLOG(1) << "initial_start_page_url: "
142 << customization.initial_start_page_url(); 162 << customization.initial_start_page_url();
143 } 163 }
144 // TODO(dpolukhin): apply customized apps, exts and support page. 164 // TODO(dpolukhin): apply customized apps, exts and support page.
145 165
146 SetApplied(true); 166 SetApplied(true);
147 } 167 }
148 168
149 } 169 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/apply_services_customization.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698