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/sync/profile_sync_service_harness.h" | 5 #include "chrome/browser/sync/profile_sync_service_harness.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <ostream> | 9 #include <ostream> |
10 #include <set> | 10 #include <set> |
11 #include <sstream> | 11 #include <sstream> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/base64.h" | 14 #include "base/base64.h" |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
18 #include "base/json/json_writer.h" | 18 #include "base/json/json_writer.h" |
19 #include "base/location.h" | 19 #include "base/location.h" |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
22 #include "base/message_loop.h" | 22 #include "base/message_loop.h" |
| 23 #include "base/prefs/pref_service.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/signin/signin_manager.h" | 25 #include "chrome/browser/signin/signin_manager_base.h" |
| 26 #include "chrome/browser/signin/token_service.h" |
| 27 #include "chrome/browser/signin/token_service_factory.h" |
25 #include "chrome/browser/sync/about_sync_util.h" | 28 #include "chrome/browser/sync/about_sync_util.h" |
26 #include "chrome/browser/sync/glue/data_type_controller.h" | 29 #include "chrome/browser/sync/glue/data_type_controller.h" |
27 #include "chrome/browser/sync/profile_sync_service_factory.h" | 30 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 31 #include "chrome/common/chrome_notification_types.h" |
28 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/pref_names.h" |
| 34 #include "content/public/browser/notification_service.h" |
| 35 #include "google_apis/gaia/gaia_constants.h" |
29 #include "sync/internal_api/public/base/progress_marker_map.h" | 36 #include "sync/internal_api/public/base/progress_marker_map.h" |
30 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | 37 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
31 #include "sync/internal_api/public/util/sync_string_conversions.h" | 38 #include "sync/internal_api/public/util/sync_string_conversions.h" |
32 | 39 |
33 using syncer::sessions::SyncSessionSnapshot; | 40 using syncer::sessions::SyncSessionSnapshot; |
34 | 41 |
35 // TODO(rsimha): Remove the following lines once crbug.com/91863 is fixed. | 42 // TODO(rsimha): Remove the following lines once crbug.com/91863 is fixed. |
36 // The amount of time for which we wait for a live sync operation to complete. | 43 // The amount of time for which we wait for a live sync operation to complete. |
37 static const int kLiveSyncOperationTimeoutMs = 45000; | 44 static const int kLiveSyncOperationTimeoutMs = 45000; |
38 | 45 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 179 |
173 // Subscribe sync client to notifications from the profile sync service. | 180 // Subscribe sync client to notifications from the profile sync service. |
174 if (!service_->HasObserver(this)) | 181 if (!service_->HasObserver(this)) |
175 service_->AddObserver(this); | 182 service_->AddObserver(this); |
176 | 183 |
177 // Tell the sync service that setup is in progress so we don't start syncing | 184 // Tell the sync service that setup is in progress so we don't start syncing |
178 // until we've finished configuration. | 185 // until we've finished configuration. |
179 service_->SetSetupInProgress(true); | 186 service_->SetSetupInProgress(true); |
180 | 187 |
181 // Authenticate sync client using GAIA credentials. | 188 // Authenticate sync client using GAIA credentials. |
182 service_->signin() | 189 service_->signin()->SetAuthenticatedUsername(username_); |
183 ->StartSignIn(username_, password_, std::string(), std::string()); | 190 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
| 191 username_); |
| 192 GoogleServiceSigninSuccessDetails details(username_, password_); |
| 193 content::NotificationService::current()->Notify( |
| 194 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
| 195 content::Source<Profile>(profile_), |
| 196 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); |
| 197 TokenServiceFactory::GetForProfile(profile_)->IssueAuthTokenForTest( |
| 198 GaiaConstants::kSyncService, "sync_token"); |
184 | 199 |
185 // Wait for the OnBackendInitialized() callback. | 200 // Wait for the OnBackendInitialized() callback. |
186 if (!AwaitBackendInitialized()) { | 201 if (!AwaitBackendInitialized()) { |
187 LOG(ERROR) << "OnBackendInitialized() not seen after " | 202 LOG(ERROR) << "OnBackendInitialized() not seen after " |
188 << kLiveSyncOperationTimeoutMs / 1000 | 203 << kLiveSyncOperationTimeoutMs / 1000 |
189 << " seconds."; | 204 << " seconds."; |
190 return false; | 205 return false; |
191 } | 206 } |
192 | 207 |
193 // Make sure that initial sync wasn't blocked by a missing passphrase. | 208 // Make sure that initial sync wasn't blocked by a missing passphrase. |
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 | 1148 |
1134 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 1149 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
1135 scoped_ptr<DictionaryValue> value( | 1150 scoped_ptr<DictionaryValue> value( |
1136 sync_ui_util::ConstructAboutInformation(service_)); | 1151 sync_ui_util::ConstructAboutInformation(service_)); |
1137 std::string service_status; | 1152 std::string service_status; |
1138 base::JSONWriter::WriteWithOptions(value.get(), | 1153 base::JSONWriter::WriteWithOptions(value.get(), |
1139 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 1154 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
1140 &service_status); | 1155 &service_status); |
1141 return service_status; | 1156 return service_status; |
1142 } | 1157 } |
OLD | NEW |