This source file includes following definitions.
- InitializeSync
- ReadPasswordFile
- AwaitQuiescence
#include "chrome/browser/extensions/api/push_messaging/sync_setup_helper.h"
#include <vector>
#include "base/file_util.h"
#include "base/strings/string_util.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/ui_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
SyncSetupHelper::SyncSetupHelper() {}
SyncSetupHelper::~SyncSetupHelper() {}
bool SyncSetupHelper::InitializeSync(Profile* profile) {
profile_ = profile;
client_.reset(
ProfileSyncServiceHarness::Create(profile_, username_, password_));
if (client_->service()->IsSyncEnabledAndLoggedIn())
return true;
if (!client_->SetupSync())
return false;
AwaitQuiescence();
return true;
}
bool SyncSetupHelper::ReadPasswordFile(const base::FilePath& password_file) {
std::string file_contents;
bool success = base::ReadFileToString(password_file, &file_contents);
EXPECT_TRUE(success)
<< "Password file \""
<< password_file.value() << "\" does not exist.";
if (!success)
return false;
std::vector<std::string> tokens;
std::string delimiters = "\r\n";
Tokenize(file_contents, delimiters, &tokens);
EXPECT_EQ(5U, tokens.size()) << "Password file \""
<< password_file.value()
<< "\" must contain exactly five lines of text.";
if (5U != tokens.size())
return false;
username_ = tokens[0];
password_ = tokens[1];
client_id_ = tokens[2];
client_secret_ = tokens[3];
refresh_token_ = tokens[4];
return true;
}
bool SyncSetupHelper::AwaitQuiescence() {
std::vector<ProfileSyncServiceHarness*> clients;
clients.push_back(client_.get());
return ProfileSyncServiceHarness::AwaitQuiescence(clients);
}
}