1 // Copyright 2014 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.
5 #include "chrome/browser/sync/test/integration/sync_extension_installer.h"
8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
13 #include "chrome/browser/sync/test/integration/sync_extension_helper.h"
14 #include "chrome/browser/sync/test/integration/sync_test.h"
15 #include "content/public/browser/notification_source.h"
17 SyncedExtensionInstaller::SyncedExtensionInstaller(Profile
* profile
)
19 weak_ptr_factory_(this) {
20 DoInstallSyncedExtensions();
22 extensions::NOTIFICATION_EXTENSION_UPDATING_STARTED
,
23 content::Source
<Profile
>(profile_
));
26 SyncedExtensionInstaller::~SyncedExtensionInstaller() {
29 void SyncedExtensionInstaller::Observe(
31 const content::NotificationSource
& source
,
32 const content::NotificationDetails
& details
) {
33 DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_UPDATING_STARTED
, type
);
35 // The extension system is trying to check for updates. In the real world,
36 // this would be where synced extensions are asynchronously downloaded from
37 // the web store and installed. In this test framework, we use this event as
38 // a signal that it's time to asynchronously fake the installation of these
41 base::ThreadTaskRunnerHandle::Get()->PostTask(
43 base::Bind(&SyncedExtensionInstaller::DoInstallSyncedExtensions
,
44 weak_ptr_factory_
.GetWeakPtr()));
47 void SyncedExtensionInstaller::DoInstallSyncedExtensions() {
48 // Do not try to install any extensions when running against real servers.
49 // We can not assume that we have a clean slate of extensions installed per
50 // profile before running the test cases.
51 if (!sync_datatype_helper::test()->UsingExternalServers()) {
52 SyncExtensionHelper::GetInstance()->
53 InstallExtensionsPendingForSync(profile_
);