OLD | NEW |
---|---|
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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 } | 169 } |
170 | 170 |
171 virtual std::string GetHTMLContents() { return contents_; } | 171 virtual std::string GetHTMLContents() { return contents_; } |
172 | 172 |
173 private: | 173 private: |
174 const std::string contents_; | 174 const std::string contents_; |
175 | 175 |
176 DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); | 176 DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); |
177 }; | 177 }; |
178 | 178 |
179 // A simple task that just signals the given event. Used to make sure all | |
180 // pending tasks on a message loop have executed after the event is signaled. | |
181 class SignalingTask : public Task { | |
Paweł Hajdan Jr.
2011/10/13 20:10:59
Huh? This is duplicating an existing class with th
Joao da Silva
2011/10/13 21:32:28
Done.
| |
182 public: | |
183 explicit SignalingTask(base::WaitableEvent* event) : event_(event) {} | |
184 | |
185 virtual void Run() OVERRIDE { | |
186 event_->Signal(); | |
187 } | |
188 | |
189 private: | |
190 base::WaitableEvent* const event_; // weak | |
191 | |
192 DISALLOW_COPY_AND_ASSIGN(SignalingTask); | |
193 }; | |
194 | |
195 // Waits until all pending tasks on |id| are executed. | |
Paweł Hajdan Jr.
2011/10/13 20:10:59
We have lots of existing code that does the same t
Joao da Silva
2011/10/13 21:32:28
Done.
| |
196 void WaitForPendingTasksOn(BrowserThread::ID id) { | |
197 CHECK(!BrowserThread::CurrentlyOn(id)); | |
Paweł Hajdan Jr.
2011/10/13 20:10:59
Instead of CHECKS, I really think you should retur
Joao da Silva
2011/10/13 21:32:28
Done.
| |
198 base::WaitableEvent event(true /* manual reset */, | |
199 false /* not initially signaled */); | |
200 CHECK(BrowserThread::PostTask(id, FROM_HERE, new SignalingTask(&event))); | |
201 event.Wait(); | |
Paweł Hajdan Jr.
2011/10/13 20:10:59
This has a return value, please check it.
Joao da Silva
2011/10/13 21:32:28
Wait() is void. A boolean is returned by TimedWait
| |
202 } | |
203 | |
179 } // namespace | 204 } // namespace |
180 | 205 |
181 TestingAutomationProvider::TestingAutomationProvider(Profile* profile) | 206 TestingAutomationProvider::TestingAutomationProvider(Profile* profile) |
182 : AutomationProvider(profile), | 207 : AutomationProvider(profile), |
183 #if defined(TOOLKIT_VIEWS) | 208 #if defined(TOOLKIT_VIEWS) |
184 popup_menu_waiter_(NULL), | 209 popup_menu_waiter_(NULL), |
185 #endif | 210 #endif |
186 redirect_query_(0) { | 211 redirect_query_(0) { |
187 BrowserList::AddObserver(this); | 212 BrowserList::AddObserver(this); |
188 registrar_.Add(this, chrome::NOTIFICATION_SESSION_END, | 213 registrar_.Add(this, chrome::NOTIFICATION_SESSION_END, |
(...skipping 2537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2726 reply.SendError("Invalid action"); | 2751 reply.SendError("Invalid action"); |
2727 } | 2752 } |
2728 | 2753 |
2729 namespace { | 2754 namespace { |
2730 | 2755 |
2731 // Task to get info about BrowserChildProcessHost. Must run on IO thread to | 2756 // Task to get info about BrowserChildProcessHost. Must run on IO thread to |
2732 // honor the semantics of BrowserChildProcessHost. | 2757 // honor the semantics of BrowserChildProcessHost. |
2733 // Used by AutomationProvider::GetBrowserInfo(). | 2758 // Used by AutomationProvider::GetBrowserInfo(). |
2734 class GetChildProcessHostInfoTask : public Task { | 2759 class GetChildProcessHostInfoTask : public Task { |
2735 public: | 2760 public: |
2736 GetChildProcessHostInfoTask(base::WaitableEvent* event, | 2761 explicit GetChildProcessHostInfoTask(ListValue* child_processes) |
2737 ListValue* child_processes) | 2762 : child_processes_(child_processes) {} |
2738 : event_(event), | |
2739 child_processes_(child_processes) {} | |
2740 | 2763 |
2741 virtual void Run() { | 2764 virtual void Run() OVERRIDE { |
2742 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2765 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2743 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { | 2766 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { |
2744 // Only add processes which are already started, | 2767 // Only add processes which are already started, |
2745 // since we need their handle. | 2768 // since we need their handle. |
2746 if ((*iter)->handle() == base::kNullProcessHandle) { | 2769 if ((*iter)->handle() == base::kNullProcessHandle) { |
2747 continue; | 2770 continue; |
2748 } | 2771 } |
2749 ChildProcessInfo* info = *iter; | 2772 ChildProcessInfo* info = *iter; |
2750 DictionaryValue* item = new DictionaryValue; | 2773 DictionaryValue* item = new DictionaryValue; |
2751 item->SetString("name", info->name()); | 2774 item->SetString("name", info->name()); |
2752 item->SetString("type", | 2775 item->SetString("type", |
2753 ChildProcessInfo::GetTypeNameInEnglish(info->type())); | 2776 ChildProcessInfo::GetTypeNameInEnglish(info->type())); |
2754 item->SetInteger("pid", base::GetProcId(info->handle())); | 2777 item->SetInteger("pid", base::GetProcId(info->handle())); |
2755 child_processes_->Append(item); | 2778 child_processes_->Append(item); |
2756 } | 2779 } |
2757 event_->Signal(); | |
2758 } | 2780 } |
2759 | 2781 |
2760 private: | 2782 private: |
2761 base::WaitableEvent* const event_; // weak | |
2762 ListValue* child_processes_; | 2783 ListValue* child_processes_; |
2763 | 2784 |
2764 DISALLOW_COPY_AND_ASSIGN(GetChildProcessHostInfoTask); | 2785 DISALLOW_COPY_AND_ASSIGN(GetChildProcessHostInfoTask); |
2765 }; | 2786 }; |
2766 | 2787 |
2767 } // namespace | 2788 } // namespace |
2768 | 2789 |
2769 // Sample json input: { "command": "GetBrowserInfo" } | 2790 // Sample json input: { "command": "GetBrowserInfo" } |
2770 // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for | 2791 // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for |
2771 // sample json output. | 2792 // sample json output. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2873 #else | 2894 #else |
2874 int flags = ChildProcessHost::CHILD_NORMAL; | 2895 int flags = ChildProcessHost::CHILD_NORMAL; |
2875 #endif | 2896 #endif |
2876 | 2897 |
2877 return_value->SetString("child_process_path", | 2898 return_value->SetString("child_process_path", |
2878 ChildProcessHost::GetChildPath(flags).value()); | 2899 ChildProcessHost::GetChildPath(flags).value()); |
2879 // Child processes are the processes for plugins and other workers. | 2900 // Child processes are the processes for plugins and other workers. |
2880 // Add all child processes in a list of dictionaries, one dictionary item | 2901 // Add all child processes in a list of dictionaries, one dictionary item |
2881 // per child process. | 2902 // per child process. |
2882 ListValue* child_processes = new ListValue; | 2903 ListValue* child_processes = new ListValue; |
2883 base::WaitableEvent event(true /* manual reset */, | |
2884 false /* not initially signaled */); | |
2885 CHECK(BrowserThread::PostTask( | 2904 CHECK(BrowserThread::PostTask( |
2886 BrowserThread::IO, FROM_HERE, | 2905 BrowserThread::IO, FROM_HERE, |
2887 new GetChildProcessHostInfoTask(&event, child_processes))); | 2906 new GetChildProcessHostInfoTask(child_processes))); |
2888 event.Wait(); | 2907 WaitForPendingTasksOn(BrowserThread::IO); |
2889 return_value->Set("child_processes", child_processes); | 2908 return_value->Set("child_processes", child_processes); |
2890 | 2909 |
2891 // Add all extension processes in a list of dictionaries, one dictionary | 2910 // Add all extension processes in a list of dictionaries, one dictionary |
2892 // item per extension process. | 2911 // item per extension process. |
2893 ListValue* extension_views = new ListValue; | 2912 ListValue* extension_views = new ListValue; |
2894 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 2913 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
2895 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); | 2914 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); |
2896 for (size_t i = 0; i < profiles.size(); ++i) { | 2915 for (size_t i = 0; i < profiles.size(); ++i) { |
2897 ExtensionProcessManager* process_manager = | 2916 ExtensionProcessManager* process_manager = |
2898 profiles[i]->GetExtensionProcessManager(); | 2917 profiles[i]->GetExtensionProcessManager(); |
(...skipping 2993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5892 } | 5911 } |
5893 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(providers); ++i) { | 5912 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(providers); ++i) { |
5894 DictionaryValue* policies = NULL; | 5913 DictionaryValue* policies = NULL; |
5895 if (args->GetDictionary(providers[i].name, &policies) && policies) { | 5914 if (args->GetDictionary(providers[i].name, &policies) && policies) { |
5896 policy::PolicyMap* map = new policy::PolicyMap; | 5915 policy::PolicyMap* map = new policy::PolicyMap; |
5897 map->LoadFrom(policies, list); | 5916 map->LoadFrom(policies, list); |
5898 providers[i].provider->OverridePolicies(map); | 5917 providers[i].provider->OverridePolicies(map); |
5899 } | 5918 } |
5900 } | 5919 } |
5901 | 5920 |
5921 // OverridePolicies() triggers preference updates, which triggers preference | |
5922 // listeners. Some policies (e.g. URLBlacklist) post tasks to other message | |
5923 // loops before they start being enforced; make sure those tasks have | |
5924 // finished. | |
5925 WaitForPendingTasksOn(BrowserThread::IO); | |
5926 WaitForPendingTasksOn(BrowserThread::FILE); | |
5927 WaitForPendingTasksOn(BrowserThread::IO); | |
5928 | |
5902 reply.SendSuccess(NULL); | 5929 reply.SendSuccess(NULL); |
5903 #endif // defined(OFFICIAL_BUILD) | 5930 #endif // defined(OFFICIAL_BUILD) |
5904 } | 5931 } |
5905 | 5932 |
5906 void TestingAutomationProvider::GetPolicyDefinitionList( | 5933 void TestingAutomationProvider::GetPolicyDefinitionList( |
5907 DictionaryValue* args, | 5934 DictionaryValue* args, |
5908 IPC::Message* reply_message) { | 5935 IPC::Message* reply_message) { |
5909 AutomationJSONReply reply(this, reply_message); | 5936 AutomationJSONReply reply(this, reply_message); |
5910 | 5937 |
5911 #if !defined(ENABLE_CONFIGURATION_POLICY) | 5938 #if !defined(ENABLE_CONFIGURATION_POLICY) |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6526 | 6553 |
6527 Send(reply_message_); | 6554 Send(reply_message_); |
6528 redirect_query_ = 0; | 6555 redirect_query_ = 0; |
6529 reply_message_ = NULL; | 6556 reply_message_ = NULL; |
6530 } | 6557 } |
6531 | 6558 |
6532 void TestingAutomationProvider::OnRemoveProvider() { | 6559 void TestingAutomationProvider::OnRemoveProvider() { |
6533 if (g_browser_process) | 6560 if (g_browser_process) |
6534 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6561 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6535 } | 6562 } |
OLD | NEW |