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

Side by Side Diff: chrome/browser/extensions/activity_log/counting_policy_unittest.cc

Issue 1395103003: Don't use base::MessageLoop::{Quit,QuitClosure} in chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/cancelable_callback.h" 5 #include "base/cancelable_callback.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 base::RunLoop().RunUntilIdle(); 62 base::RunLoop().RunUntilIdle();
63 profile_.reset(NULL); 63 profile_.reset(NULL);
64 base::RunLoop().RunUntilIdle(); 64 base::RunLoop().RunUntilIdle();
65 // Restore the original command line and undo the affects of SetUp(). 65 // Restore the original command line and undo the affects of SetUp().
66 *base::CommandLine::ForCurrentProcess() = saved_cmdline_; 66 *base::CommandLine::ForCurrentProcess() = saved_cmdline_;
67 } 67 }
68 68
69 // Wait for the task queue for the specified thread to empty. 69 // Wait for the task queue for the specified thread to empty.
70 void WaitOnThread(const BrowserThread::ID& thread) { 70 void WaitOnThread(const BrowserThread::ID& thread) {
71 BrowserThread::PostTaskAndReply( 71 BrowserThread::PostTaskAndReply(
72 thread, 72 thread, FROM_HERE, base::Bind(&base::DoNothing),
73 FROM_HERE, 73 base::MessageLoop::current()->QuitWhenIdleClosure());
74 base::Bind(&base::DoNothing),
75 base::MessageLoop::current()->QuitClosure());
76 base::MessageLoop::current()->Run(); 74 base::MessageLoop::current()->Run();
77 } 75 }
78 76
79 // A wrapper function for CheckReadFilteredData, so that we don't need to 77 // A wrapper function for CheckReadFilteredData, so that we don't need to
80 // enter empty string values for parameters we don't care about. 78 // enter empty string values for parameters we don't care about.
81 void CheckReadData( 79 void CheckReadData(
82 ActivityLogDatabasePolicy* policy, 80 ActivityLogDatabasePolicy* policy,
83 const std::string& extension_id, 81 const std::string& extension_id,
84 int day, 82 int day,
85 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) { 83 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) {
86 CheckReadFilteredData( 84 CheckReadFilteredData(
87 policy, extension_id, Action::ACTION_ANY, "", "", "", day, checker); 85 policy, extension_id, Action::ACTION_ANY, "", "", "", day, checker);
88 } 86 }
89 87
90 // A helper function to call ReadFilteredData on a policy object and wait for 88 // A helper function to call ReadFilteredData on a policy object and wait for
91 // the results to be processed. 89 // the results to be processed.
92 void CheckReadFilteredData( 90 void CheckReadFilteredData(
93 ActivityLogDatabasePolicy* policy, 91 ActivityLogDatabasePolicy* policy,
94 const std::string& extension_id, 92 const std::string& extension_id,
95 const Action::ActionType type, 93 const Action::ActionType type,
96 const std::string& api_name, 94 const std::string& api_name,
97 const std::string& page_url, 95 const std::string& page_url,
98 const std::string& arg_url, 96 const std::string& arg_url,
99 int day, 97 int day,
100 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) { 98 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) {
101 // Submit a request to the policy to read back some data, and call the 99 // Submit a request to the policy to read back some data, and call the
102 // checker function when results are available. This will happen on the 100 // checker function when results are available. This will happen on the
103 // database thread. 101 // database thread.
104 policy->ReadFilteredData( 102 policy->ReadFilteredData(
105 extension_id, 103 extension_id, type, api_name, page_url, arg_url, day,
106 type, 104 base::Bind(&CountingPolicyTest::CheckWrapper, checker,
107 api_name, 105 base::MessageLoop::current()->QuitWhenIdleClosure()));
108 page_url,
109 arg_url,
110 day,
111 base::Bind(&CountingPolicyTest::CheckWrapper,
112 checker,
113 base::MessageLoop::current()->QuitClosure()));
114 106
115 // Set up a timeout for receiving results; if we haven't received anything 107 // Set up a timeout for receiving results; if we haven't received anything
116 // when the timeout triggers then assume that the test is broken. 108 // when the timeout triggers then assume that the test is broken.
117 base::CancelableClosure timeout( 109 base::CancelableClosure timeout(
118 base::Bind(&CountingPolicyTest::TimeoutCallback)); 110 base::Bind(&CountingPolicyTest::TimeoutCallback));
119 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 111 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
120 FROM_HERE, timeout.callback(), TestTimeouts::action_timeout()); 112 FROM_HERE, timeout.callback(), TestTimeouts::action_timeout());
121 113
122 // Wait for results; either the checker or the timeout callbacks should 114 // Wait for results; either the checker or the timeout callbacks should
123 // cause the main loop to exit. 115 // cause the main loop to exit.
(...skipping 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 1409
1418 action_ids.push_back(2); 1410 action_ids.push_back(2);
1419 CheckRemoveActions( 1411 CheckRemoveActions(
1420 policy, action_ids, base::Bind(&CountingPolicyTest::Action2Deleted)); 1412 policy, action_ids, base::Bind(&CountingPolicyTest::Action2Deleted));
1421 action_ids.clear(); 1413 action_ids.clear();
1422 1414
1423 policy->Close(); 1415 policy->Close();
1424 } 1416 }
1425 1417
1426 } // namespace extensions 1418 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698