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

Side by Side Diff: chrome/browser/extensions/api/push_messaging/sync_setup_helper.cc

Issue 1018643003: Removing chrome.pushMessaging API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updates to documentation per kalman's comments Created 5 years, 9 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/api/push_messaging/sync_setup_helper.h"
6
7 #include <vector>
8
9 #include "base/files/file_util.h"
10 #include "base/strings/string_util.h"
11 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/history/history_service_factory.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/search_engines/template_url_service_factory.h"
17 #include "chrome/browser/sync/profile_sync_service.h"
18 #include "chrome/browser/sync/profile_sync_service_factory.h"
19 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/common/chrome_paths.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23
24 namespace extensions {
25
26 SyncSetupHelper::SyncSetupHelper() {}
27
28 SyncSetupHelper::~SyncSetupHelper() {}
29
30 bool SyncSetupHelper::InitializeSync(Profile* profile) {
31 profile_ = profile;
32 client_.reset(ProfileSyncServiceHarness::Create(
33 profile_,
34 username_,
35 password_,
36 ProfileSyncServiceHarness::SigninType::FAKE_SIGNIN));
37
38 if (client_->service()->IsSyncEnabledAndLoggedIn())
39 return true;
40
41 if (!client_->SetupSync())
42 return false;
43
44 // Because clients may modify sync data as part of startup (for example local
45 // session-releated data is rewritten), we need to ensure all startup-based
46 // changes have propagated between the clients.
47 // This could take several seconds.
48 AwaitQuiescence();
49 return true;
50 }
51
52 // Read the sync signin credentials from a file on the machine.
53 bool SyncSetupHelper::ReadPasswordFile(const base::FilePath& password_file) {
54 // TODO(dcheng): Convert format of config file to JSON.
55 std::string file_contents;
56 bool success = base::ReadFileToString(password_file, &file_contents);
57 EXPECT_TRUE(success)
58 << "Password file \""
59 << password_file.value() << "\" does not exist.";
60 if (!success)
61 return false;
62
63 std::vector<std::string> tokens;
64 std::string delimiters = "\r\n";
65 Tokenize(file_contents, delimiters, &tokens);
66 EXPECT_EQ(5U, tokens.size()) << "Password file \""
67 << password_file.value()
68 << "\" must contain exactly five lines of text.";
69 if (5U != tokens.size())
70 return false;
71 username_ = tokens[0];
72 password_ = tokens[1];
73 client_id_ = tokens[2];
74 client_secret_ = tokens[3];
75 refresh_token_ = tokens[4];
76 return true;
77 }
78
79 bool SyncSetupHelper::AwaitQuiescence() {
80 std::vector<ProfileSyncServiceHarness*> clients;
81 clients.push_back(client_.get());
82 return ProfileSyncServiceHarness::AwaitQuiescence(clients);
83 }
84
85 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698