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

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 8274012: Wait for URLBlacklist update tasks on automation tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added BrowserThread::WaitForPendingTasksOn, removed SignalingTask Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/automation/testing_automation_provider.h" 5 #include "chrome/browser/automation/testing_automation_provider.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 2715 matching lines...) Expand 10 before | Expand all | Expand 10 after
2726 reply.SendError("Invalid action"); 2726 reply.SendError("Invalid action");
2727 } 2727 }
2728 2728
2729 namespace { 2729 namespace {
2730 2730
2731 // Task to get info about BrowserChildProcessHost. Must run on IO thread to 2731 // Task to get info about BrowserChildProcessHost. Must run on IO thread to
2732 // honor the semantics of BrowserChildProcessHost. 2732 // honor the semantics of BrowserChildProcessHost.
2733 // Used by AutomationProvider::GetBrowserInfo(). 2733 // Used by AutomationProvider::GetBrowserInfo().
2734 class GetChildProcessHostInfoTask : public Task { 2734 class GetChildProcessHostInfoTask : public Task {
2735 public: 2735 public:
2736 GetChildProcessHostInfoTask(base::WaitableEvent* event, 2736 explicit GetChildProcessHostInfoTask(ListValue* child_processes)
2737 ListValue* child_processes) 2737 : child_processes_(child_processes) {}
2738 : event_(event),
2739 child_processes_(child_processes) {}
2740 2738
2741 virtual void Run() { 2739 virtual void Run() OVERRIDE {
2742 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 2740 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2743 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { 2741 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) {
2744 // Only add processes which are already started, 2742 // Only add processes which are already started,
2745 // since we need their handle. 2743 // since we need their handle.
2746 if ((*iter)->handle() == base::kNullProcessHandle) { 2744 if ((*iter)->handle() == base::kNullProcessHandle) {
2747 continue; 2745 continue;
2748 } 2746 }
2749 ChildProcessInfo* info = *iter; 2747 ChildProcessInfo* info = *iter;
2750 DictionaryValue* item = new DictionaryValue; 2748 DictionaryValue* item = new DictionaryValue;
2751 item->SetString("name", info->name()); 2749 item->SetString("name", info->name());
2752 item->SetString("type", 2750 item->SetString("type",
2753 ChildProcessInfo::GetTypeNameInEnglish(info->type())); 2751 ChildProcessInfo::GetTypeNameInEnglish(info->type()));
2754 item->SetInteger("pid", base::GetProcId(info->handle())); 2752 item->SetInteger("pid", base::GetProcId(info->handle()));
2755 child_processes_->Append(item); 2753 child_processes_->Append(item);
2756 } 2754 }
2757 event_->Signal();
2758 } 2755 }
2759 2756
2760 private: 2757 private:
2761 base::WaitableEvent* const event_; // weak
2762 ListValue* child_processes_; 2758 ListValue* child_processes_;
2763 2759
2764 DISALLOW_COPY_AND_ASSIGN(GetChildProcessHostInfoTask); 2760 DISALLOW_COPY_AND_ASSIGN(GetChildProcessHostInfoTask);
2765 }; 2761 };
2766 2762
2767 } // namespace 2763 } // namespace
2768 2764
2769 // Sample json input: { "command": "GetBrowserInfo" } 2765 // Sample json input: { "command": "GetBrowserInfo" }
2770 // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for 2766 // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for
2771 // sample json output. 2767 // sample json output.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2873 #else 2869 #else
2874 int flags = ChildProcessHost::CHILD_NORMAL; 2870 int flags = ChildProcessHost::CHILD_NORMAL;
2875 #endif 2871 #endif
2876 2872
2877 return_value->SetString("child_process_path", 2873 return_value->SetString("child_process_path",
2878 ChildProcessHost::GetChildPath(flags).value()); 2874 ChildProcessHost::GetChildPath(flags).value());
2879 // Child processes are the processes for plugins and other workers. 2875 // Child processes are the processes for plugins and other workers.
2880 // Add all child processes in a list of dictionaries, one dictionary item 2876 // Add all child processes in a list of dictionaries, one dictionary item
2881 // per child process. 2877 // per child process.
2882 ListValue* child_processes = new ListValue; 2878 ListValue* child_processes = new ListValue;
2883 base::WaitableEvent event(true /* manual reset */,
2884 false /* not initially signaled */);
2885 CHECK(BrowserThread::PostTask( 2879 CHECK(BrowserThread::PostTask(
2886 BrowserThread::IO, FROM_HERE, 2880 BrowserThread::IO, FROM_HERE,
2887 new GetChildProcessHostInfoTask(&event, child_processes))); 2881 new GetChildProcessHostInfoTask(child_processes)));
2888 event.Wait(); 2882 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::IO));
2889 return_value->Set("child_processes", child_processes); 2883 return_value->Set("child_processes", child_processes);
2890 2884
2891 // Add all extension processes in a list of dictionaries, one dictionary 2885 // Add all extension processes in a list of dictionaries, one dictionary
2892 // item per extension process. 2886 // item per extension process.
2893 ListValue* extension_views = new ListValue; 2887 ListValue* extension_views = new ListValue;
2894 ProfileManager* profile_manager = g_browser_process->profile_manager(); 2888 ProfileManager* profile_manager = g_browser_process->profile_manager();
2895 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); 2889 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles());
2896 for (size_t i = 0; i < profiles.size(); ++i) { 2890 for (size_t i = 0; i < profiles.size(); ++i) {
2897 ExtensionProcessManager* process_manager = 2891 ExtensionProcessManager* process_manager =
2898 profiles[i]->GetExtensionProcessManager(); 2892 profiles[i]->GetExtensionProcessManager();
(...skipping 2993 matching lines...) Expand 10 before | Expand all | Expand 10 after
5892 } 5886 }
5893 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(providers); ++i) { 5887 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(providers); ++i) {
5894 DictionaryValue* policies = NULL; 5888 DictionaryValue* policies = NULL;
5895 if (args->GetDictionary(providers[i].name, &policies) && policies) { 5889 if (args->GetDictionary(providers[i].name, &policies) && policies) {
5896 policy::PolicyMap* map = new policy::PolicyMap; 5890 policy::PolicyMap* map = new policy::PolicyMap;
5897 map->LoadFrom(policies, list); 5891 map->LoadFrom(policies, list);
5898 providers[i].provider->OverridePolicies(map); 5892 providers[i].provider->OverridePolicies(map);
5899 } 5893 }
5900 } 5894 }
5901 5895
5896 // OverridePolicies() triggers preference updates, which triggers preference
5897 // listeners. Some policies (e.g. URLBlacklist) post tasks to other message
5898 // loops before they start being enforced; make sure those tasks have
5899 // finished.
5900 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::IO));
5901 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::FILE));
5902 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::IO));
5903
5902 reply.SendSuccess(NULL); 5904 reply.SendSuccess(NULL);
5903 #endif // defined(OFFICIAL_BUILD) 5905 #endif // defined(OFFICIAL_BUILD)
5904 } 5906 }
5905 5907
5906 void TestingAutomationProvider::GetPolicyDefinitionList( 5908 void TestingAutomationProvider::GetPolicyDefinitionList(
5907 DictionaryValue* args, 5909 DictionaryValue* args,
5908 IPC::Message* reply_message) { 5910 IPC::Message* reply_message) {
5909 AutomationJSONReply reply(this, reply_message); 5911 AutomationJSONReply reply(this, reply_message);
5910 5912
5911 #if !defined(ENABLE_CONFIGURATION_POLICY) 5913 #if !defined(ENABLE_CONFIGURATION_POLICY)
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
6526 6528
6527 Send(reply_message_); 6529 Send(reply_message_);
6528 redirect_query_ = 0; 6530 redirect_query_ = 0;
6529 reply_message_ = NULL; 6531 reply_message_ = NULL;
6530 } 6532 }
6531 6533
6532 void TestingAutomationProvider::OnRemoveProvider() { 6534 void TestingAutomationProvider::OnRemoveProvider() {
6533 if (g_browser_process) 6535 if (g_browser_process)
6534 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 6536 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6535 } 6537 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/test_extension_prefs.cc » ('j') | content/browser/browser_thread.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698