OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 "content/public/test/background_sync_test_util.h" | |
6 | |
7 #include "base/run_loop.h" | |
8 #include "base/task_runner_util.h" | |
9 #include "content/browser/background_sync/background_sync_manager.h" | |
10 #include "content/browser/background_sync/background_sync_network_observer.h" | |
11 #include "content/browser/background_sync/background_sync_registration_handle.h" | |
12 #include "content/public/browser/background_sync_context.h" | |
13 #include "content/public/browser/browser_context.h" | |
14 #include "content/public/browser/browser_thread.h" | |
15 #include "content/public/browser/storage_partition.h" | |
16 #include "content/public/browser/web_contents.h" | |
17 #include "net/base/network_change_notifier.h" | |
18 | |
19 using content::BackgroundSyncManager; | |
Devlin
2015/11/16 18:12:41
Let's just put the anonymous namespace at line 26
lazyboy
2015/11/16 19:30:16
Done.
| |
20 using content::BackgroundSyncNetworkObserver; | |
21 using content::BrowserContext; | |
22 using content::BrowserThread; | |
23 using content::StoragePartition; | |
24 using content::WebContents; | |
25 | |
26 namespace { | |
27 | |
28 void SetOnlineOnIOThread( | |
29 const scoped_refptr<content::BackgroundSyncContext>& sync_context, | |
30 bool online) { | |
31 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
32 | |
33 BackgroundSyncManager* sync_manager = sync_context->background_sync_manager(); | |
34 BackgroundSyncNetworkObserver* network_observer = | |
35 sync_manager->GetNetworkObserverForTesting(); | |
36 if (online) { | |
37 network_observer->NotifyManagerIfNetworkChangedForTesting( | |
38 net::NetworkChangeNotifier::CONNECTION_WIFI); | |
39 } else { | |
40 network_observer->NotifyManagerIfNetworkChangedForTesting( | |
41 net::NetworkChangeNotifier::CONNECTION_NONE); | |
42 } | |
43 } | |
44 | |
45 StoragePartition* GetStoragePartition(WebContents* web_contents) { | |
46 return BrowserContext::GetStoragePartition(web_contents->GetBrowserContext(), | |
47 web_contents->GetSiteInstance()); | |
48 } | |
49 | |
50 } // namespace | |
51 | |
52 namespace content { | |
53 | |
54 // static. | |
55 void BackgroundSyncTestUtil::SetIgnoreNetworkChangeNotifier(bool ignore) { | |
56 BackgroundSyncNetworkObserver::SetIgnoreNetworkChangeNotifierForTests(ignore); | |
57 } | |
58 | |
59 // static. | |
60 void BackgroundSyncTestUtil::SetOnline(WebContents* web_contents, bool online) { | |
61 BrowserThread::PostTask( | |
62 BrowserThread::IO, FROM_HERE, | |
63 base::Bind(&SetOnlineOnIOThread, | |
64 base::Unretained(GetStoragePartition(web_contents) | |
65 ->GetBackgroundSyncContext()), | |
66 online)); | |
67 base::RunLoop().RunUntilIdle(); | |
68 } | |
69 | |
70 } // namespace content | |
OLD | NEW |