OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/sync/sync_setup_wizard.h" | 5 #include "chrome/browser/sync/sync_setup_wizard.h" |
6 | 6 |
7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/singleton.h" | 9 #include "base/singleton.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
11 #include "chrome/common/pref_service.h" | 11 #include "chrome/common/pref_service.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/chrome_thread.h" |
13 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 13 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
14 #include "chrome/browser/sync/profile_sync_service.h" | 14 #include "chrome/browser/sync/profile_sync_service.h" |
15 #include "chrome/browser/sync/sync_setup_flow.h" | 15 #include "chrome/browser/sync/sync_setup_flow.h" |
16 #include "chrome/common/jstemplate_builder.h" | 16 #include "chrome/common/jstemplate_builder.h" |
17 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
18 #include "grit/app_resources.h" | 18 #include "grit/app_resources.h" |
19 #include "grit/browser_resources.h" | 19 #include "grit/browser_resources.h" |
20 | 20 |
21 class SyncResourcesSource : public ChromeURLDataManager::DataSource { | 21 class SyncResourcesSource : public ChromeURLDataManager::DataSource { |
22 public: | 22 public: |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 130 } |
131 // Send the response. | 131 // Send the response. |
132 html_bytes->data.resize(response.size()); | 132 html_bytes->data.resize(response.size()); |
133 std::copy(response.begin(), response.end(), html_bytes->data.begin()); | 133 std::copy(response.begin(), response.end(), html_bytes->data.begin()); |
134 SendResponse(request_id, html_bytes); | 134 SendResponse(request_id, html_bytes); |
135 } | 135 } |
136 | 136 |
137 SyncSetupWizard::SyncSetupWizard(ProfileSyncService* service) | 137 SyncSetupWizard::SyncSetupWizard(ProfileSyncService* service) |
138 : service_(service), | 138 : service_(service), |
139 flow_container_(new SyncSetupFlowContainer()) { | 139 flow_container_(new SyncSetupFlowContainer()) { |
140 // Register data sources for HTML content we require. | 140 // Add our network layer data source for 'cloudy' URLs. |
141 // g_browser_process and/or io_thread may not exist during testing. | 141 SyncResourcesSource* sync_source = new SyncResourcesSource(); |
142 if (g_browser_process && g_browser_process->io_thread()) { | 142 bool posted = ChromeThread::PostTask( |
143 // Add our network layer data source for 'cloudy' URLs. | 143 ChromeThread::IO, FROM_HERE, |
144 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 144 NewRunnableMethod(Singleton<ChromeURLDataManager>().get(), |
145 NewRunnableMethod(Singleton<ChromeURLDataManager>().get(), | 145 &ChromeURLDataManager::AddDataSource, |
146 &ChromeURLDataManager::AddDataSource, | 146 sync_source)); |
147 new SyncResourcesSource())); | 147 if (!posted) { |
| 148 sync_source->AddRef(); |
| 149 sync_source->Release(); // Keep Valgrind happy in unit tests. |
148 } | 150 } |
149 } | 151 } |
150 | 152 |
151 SyncSetupWizard::~SyncSetupWizard() { | 153 SyncSetupWizard::~SyncSetupWizard() { |
152 delete flow_container_; | 154 delete flow_container_; |
153 } | 155 } |
154 | 156 |
155 void SyncSetupWizard::Step(State advance_state) { | 157 void SyncSetupWizard::Step(State advance_state) { |
156 SyncSetupFlow* flow = flow_container_->get_flow(); | 158 SyncSetupFlow* flow = flow_container_->get_flow(); |
157 if (flow) { | 159 if (flow) { |
(...skipping 30 matching lines...) Expand all Loading... |
188 } | 190 } |
189 | 191 |
190 // static | 192 // static |
191 SyncSetupWizard::State SyncSetupWizard::GetEndStateForDiscreteRun( | 193 SyncSetupWizard::State SyncSetupWizard::GetEndStateForDiscreteRun( |
192 State start_state) { | 194 State start_state) { |
193 State result = start_state == GAIA_LOGIN ? GAIA_SUCCESS : DONE; | 195 State result = start_state == GAIA_LOGIN ? GAIA_SUCCESS : DONE; |
194 DCHECK_NE(DONE, result) << | 196 DCHECK_NE(DONE, result) << |
195 "Invalid start state for discrete run: " << start_state; | 197 "Invalid start state for discrete run: " << start_state; |
196 return result; | 198 return result; |
197 } | 199 } |
OLD | NEW |