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

Side by Side Diff: content/browser/background_sync/background_sync_browsertest.cc

Issue 2954433002: BackgroundSync: Convert to base::BindOnce/OnceCallback/OnceClosure (Closed)
Patch Set: rename local variable Created 3 years, 5 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
« no previous file with comments | « no previous file | content/browser/background_sync/background_sync_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 const base::Closure& quit, 65 const base::Closure& quit,
66 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 66 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
67 bool* result_out, 67 bool* result_out,
68 bool result) { 68 bool result) {
69 *result_out = result; 69 *result_out = result;
70 task_runner->PostTask(FROM_HERE, quit); 70 task_runner->PostTask(FROM_HERE, quit);
71 } 71 }
72 72
73 void RegistrationPendingDidGetSyncRegistration( 73 void RegistrationPendingDidGetSyncRegistration(
74 const std::string& tag, 74 const std::string& tag,
75 const base::Callback<void(bool)>& callback, 75 base::OnceCallback<void(bool)> callback,
76 BackgroundSyncStatus error_type, 76 BackgroundSyncStatus error_type,
77 std::vector<std::unique_ptr<BackgroundSyncRegistration>> registrations) { 77 std::vector<std::unique_ptr<BackgroundSyncRegistration>> registrations) {
78 ASSERT_EQ(BACKGROUND_SYNC_STATUS_OK, error_type); 78 ASSERT_EQ(BACKGROUND_SYNC_STATUS_OK, error_type);
79 // Find the right registration in the list and check its status. 79 // Find the right registration in the list and check its status.
80 for (const auto& registration : registrations) { 80 for (const auto& registration : registrations) {
81 if (registration->options()->tag == tag) { 81 if (registration->options()->tag == tag) {
82 callback.Run(registration->sync_state() == 82 std::move(callback).Run(registration->sync_state() ==
83 blink::mojom::BackgroundSyncState::PENDING); 83 blink::mojom::BackgroundSyncState::PENDING);
84 return; 84 return;
85 } 85 }
86 } 86 }
87 ADD_FAILURE() << "Registration should exist"; 87 ADD_FAILURE() << "Registration should exist";
88 } 88 }
89 89
90 void RegistrationPendingDidGetSWRegistration( 90 void RegistrationPendingDidGetSWRegistration(
91 const scoped_refptr<BackgroundSyncContext> sync_context, 91 const scoped_refptr<BackgroundSyncContext> sync_context,
92 const std::string& tag, 92 const std::string& tag,
93 const base::Callback<void(bool)>& callback, 93 base::OnceCallback<void(bool)> callback,
94 ServiceWorkerStatusCode status, 94 ServiceWorkerStatusCode status,
95 scoped_refptr<ServiceWorkerRegistration> registration) { 95 scoped_refptr<ServiceWorkerRegistration> registration) {
96 ASSERT_EQ(SERVICE_WORKER_OK, status); 96 ASSERT_EQ(SERVICE_WORKER_OK, status);
97 int64_t service_worker_id = registration->id(); 97 int64_t service_worker_id = registration->id();
98 BackgroundSyncManager* sync_manager = sync_context->background_sync_manager(); 98 BackgroundSyncManager* sync_manager = sync_context->background_sync_manager();
99 sync_manager->GetRegistrations( 99 sync_manager->GetRegistrations(
100 service_worker_id, 100 service_worker_id,
101 base::Bind(&RegistrationPendingDidGetSyncRegistration, tag, callback)); 101 base::BindOnce(&RegistrationPendingDidGetSyncRegistration, tag,
102 std::move(callback)));
102 } 103 }
103 104
104 void RegistrationPendingOnIOThread( 105 void RegistrationPendingOnIOThread(
105 const scoped_refptr<BackgroundSyncContext> sync_context, 106 const scoped_refptr<BackgroundSyncContext> sync_context,
106 const scoped_refptr<ServiceWorkerContextWrapper> sw_context, 107 const scoped_refptr<ServiceWorkerContextWrapper> sw_context,
107 const std::string& tag, 108 const std::string& tag,
108 const GURL& url, 109 const GURL& url,
109 const base::Callback<void(bool)>& callback) { 110 base::OnceCallback<void(bool)> callback) {
110 sw_context->FindReadyRegistrationForDocument( 111 sw_context->FindReadyRegistrationForDocument(
111 url, base::Bind(&RegistrationPendingDidGetSWRegistration, sync_context, 112 url, base::AdaptCallbackForRepeating(
112 tag, callback)); 113 base::BindOnce(&RegistrationPendingDidGetSWRegistration,
114 sync_context, tag, std::move(callback))));
113 } 115 }
114 116
115 void SetMaxSyncAttemptsOnIOThread( 117 void SetMaxSyncAttemptsOnIOThread(
116 const scoped_refptr<BackgroundSyncContext>& sync_context, 118 const scoped_refptr<BackgroundSyncContext>& sync_context,
117 int max_sync_attempts) { 119 int max_sync_attempts) {
118 BackgroundSyncManager* background_sync_manager = 120 BackgroundSyncManager* background_sync_manager =
119 sync_context->background_sync_manager(); 121 sync_context->background_sync_manager();
120 background_sync_manager->SetMaxSyncAttemptsForTesting(max_sync_attempts); 122 background_sync_manager->SetMaxSyncAttemptsForTesting(max_sync_attempts);
121 } 123 }
122 124
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 bool BackgroundSyncBrowserTest::RegistrationPending(const std::string& tag) { 221 bool BackgroundSyncBrowserTest::RegistrationPending(const std::string& tag) {
220 bool is_pending; 222 bool is_pending;
221 base::RunLoop run_loop; 223 base::RunLoop run_loop;
222 224
223 StoragePartitionImpl* storage = GetStorage(); 225 StoragePartitionImpl* storage = GetStorage();
224 BackgroundSyncContext* sync_context = storage->GetBackgroundSyncContext(); 226 BackgroundSyncContext* sync_context = storage->GetBackgroundSyncContext();
225 ServiceWorkerContextWrapper* service_worker_context = 227 ServiceWorkerContextWrapper* service_worker_context =
226 static_cast<ServiceWorkerContextWrapper*>( 228 static_cast<ServiceWorkerContextWrapper*>(
227 storage->GetServiceWorkerContext()); 229 storage->GetServiceWorkerContext());
228 230
229 base::Callback<void(bool)> callback = 231 auto callback =
230 base::Bind(&RegistrationPendingCallback, run_loop.QuitClosure(), 232 base::BindOnce(&RegistrationPendingCallback, run_loop.QuitClosure(),
231 base::ThreadTaskRunnerHandle::Get(), &is_pending); 233 base::ThreadTaskRunnerHandle::Get(), &is_pending);
232 234
233 BrowserThread::PostTask( 235 BrowserThread::PostTask(
234 BrowserThread::IO, FROM_HERE, 236 BrowserThread::IO, FROM_HERE,
235 base::Bind(&RegistrationPendingOnIOThread, 237 base::BindOnce(
236 make_scoped_refptr(sync_context), 238 &RegistrationPendingOnIOThread, make_scoped_refptr(sync_context),
237 make_scoped_refptr(service_worker_context), tag, 239 make_scoped_refptr(service_worker_context), tag,
238 https_server_->GetURL(kDefaultTestURL), callback)); 240 https_server_->GetURL(kDefaultTestURL), std::move(callback)));
239 241
240 run_loop.Run(); 242 run_loop.Run();
241 243
242 return is_pending; 244 return is_pending;
243 } 245 }
244 246
245 void BackgroundSyncBrowserTest::SetMaxSyncAttempts(int max_sync_attempts) { 247 void BackgroundSyncBrowserTest::SetMaxSyncAttempts(int max_sync_attempts) {
246 base::RunLoop run_loop; 248 base::RunLoop run_loop;
247 249
248 StoragePartitionImpl* storage = GetStorage(); 250 StoragePartitionImpl* storage = GetStorage();
249 BackgroundSyncContext* sync_context = storage->GetBackgroundSyncContext(); 251 BackgroundSyncContext* sync_context = storage->GetBackgroundSyncContext();
250 252
251 BrowserThread::PostTaskAndReply( 253 BrowserThread::PostTaskAndReply(
252 BrowserThread::IO, FROM_HERE, 254 BrowserThread::IO, FROM_HERE,
253 base::Bind(&SetMaxSyncAttemptsOnIOThread, 255 base::BindOnce(&SetMaxSyncAttemptsOnIOThread,
254 make_scoped_refptr(sync_context), max_sync_attempts), 256 make_scoped_refptr(sync_context), max_sync_attempts),
255 run_loop.QuitClosure()); 257 run_loop.QuitClosure());
256 258
257 run_loop.Run(); 259 run_loop.Run();
258 } 260 }
259 261
260 void BackgroundSyncBrowserTest::ClearStoragePartitionData() { 262 void BackgroundSyncBrowserTest::ClearStoragePartitionData() {
261 // Clear data from the storage partition. Parameters are set to clear data 263 // Clear data from the storage partition. Parameters are set to clear data
262 // for service workers, for all origins, for an unbounded time range. 264 // for service workers, for all origins, for an unbounded time range.
263 StoragePartitionImpl* storage = GetStorage(); 265 StoragePartitionImpl* storage = GetStorage();
264 266
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, 684 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest,
683 RegisterFromServiceWorkerWithoutMainFrameHost) { 685 RegisterFromServiceWorkerWithoutMainFrameHost) {
684 std::string script_result; 686 std::string script_result;
685 EXPECT_TRUE( 687 EXPECT_TRUE(
686 RegisterFromCrossOriginFrame(kRegisterSyncFromSWURL, &script_result)); 688 RegisterFromCrossOriginFrame(kRegisterSyncFromSWURL, &script_result));
687 EXPECT_EQ(BuildExpectedResult("frame", "failed to register sync"), 689 EXPECT_EQ(BuildExpectedResult("frame", "failed to register sync"),
688 script_result); 690 script_result);
689 } 691 }
690 692
691 } // namespace content 693 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/background_sync/background_sync_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698