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 // Helper function for nested Binds that resolves the overloading of | |
180 // BrowserThread::PostTask, and ignores the return value. | |
Joao da Silva
2011/10/21 12:59:58
I tried to resolve the overloading with
bool (*po
| |
181 void PostTask(BrowserThread::ID id, const base::Closure& task) { | |
182 CHECK(BrowserThread::PostTask(id, FROM_HERE, task)); | |
Paweł Hajdan Jr.
2011/10/21 15:13:17
Please make it return the value it gets from the r
| |
183 } | |
184 | |
179 } // namespace | 185 } // namespace |
180 | 186 |
181 TestingAutomationProvider::TestingAutomationProvider(Profile* profile) | 187 TestingAutomationProvider::TestingAutomationProvider(Profile* profile) |
182 : AutomationProvider(profile), | 188 : AutomationProvider(profile), |
183 #if defined(TOOLKIT_VIEWS) | 189 #if defined(TOOLKIT_VIEWS) |
184 popup_menu_waiter_(NULL), | 190 popup_menu_waiter_(NULL), |
185 #endif | 191 #endif |
186 redirect_query_(0) { | 192 redirect_query_(0) { |
187 BrowserList::AddObserver(this); | 193 BrowserList::AddObserver(this); |
188 registrar_.Add(this, chrome::NOTIFICATION_SESSION_END, | 194 registrar_.Add(this, chrome::NOTIFICATION_SESSION_END, |
(...skipping 2534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2723 infobar_helper->RemoveInfoBar(infobar); | 2729 infobar_helper->RemoveInfoBar(infobar); |
2724 } | 2730 } |
2725 reply.SendSuccess(NULL); | 2731 reply.SendSuccess(NULL); |
2726 return; | 2732 return; |
2727 } | 2733 } |
2728 reply.SendError("Invalid action"); | 2734 reply.SendError("Invalid action"); |
2729 } | 2735 } |
2730 | 2736 |
2731 namespace { | 2737 namespace { |
2732 | 2738 |
2733 // Task to get info about BrowserChildProcessHost. Must run on IO thread to | 2739 // Gets info about BrowserChildProcessHost. Must run on IO thread to |
2734 // honor the semantics of BrowserChildProcessHost. | 2740 // honor the semantics of BrowserChildProcessHost. |
2735 // Used by AutomationProvider::GetBrowserInfo(). | 2741 // Used by AutomationProvider::GetBrowserInfo(). |
2736 class GetChildProcessHostInfoTask : public Task { | 2742 void GetChildProcessHostInfo(ListValue* child_processes) { |
2737 public: | 2743 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2738 GetChildProcessHostInfoTask(base::WaitableEvent* event, | 2744 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { |
2739 ListValue* child_processes) | 2745 // Only add processes which are already started, |
2740 : event_(event), | 2746 // since we need their handle. |
2741 child_processes_(child_processes) {} | 2747 if ((*iter)->handle() == base::kNullProcessHandle) { |
Paweł Hajdan Jr.
2011/10/21 15:13:17
nit: No need for braces {}.
Joao da Silva
2011/10/22 11:26:50
Done.
| |
2742 | 2748 continue; |
2743 virtual void Run() { | |
2744 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
2745 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { | |
2746 // Only add processes which are already started, | |
2747 // since we need their handle. | |
2748 if ((*iter)->handle() == base::kNullProcessHandle) { | |
2749 continue; | |
2750 } | |
2751 ChildProcessInfo* info = *iter; | |
2752 DictionaryValue* item = new DictionaryValue; | |
2753 item->SetString("name", info->name()); | |
2754 item->SetString("type", | |
2755 ChildProcessInfo::GetTypeNameInEnglish(info->type())); | |
2756 item->SetInteger("pid", base::GetProcId(info->handle())); | |
2757 child_processes_->Append(item); | |
2758 } | 2749 } |
2759 event_->Signal(); | 2750 ChildProcessInfo* info = *iter; |
2751 DictionaryValue* item = new DictionaryValue; | |
2752 item->SetString("name", info->name()); | |
2753 item->SetString("type", | |
2754 ChildProcessInfo::GetTypeNameInEnglish(info->type())); | |
2755 item->SetInteger("pid", base::GetProcId(info->handle())); | |
2756 child_processes->Append(item); | |
2760 } | 2757 } |
2761 | 2758 } |
2762 private: | |
2763 base::WaitableEvent* const event_; // weak | |
2764 ListValue* child_processes_; | |
2765 | |
2766 DISALLOW_COPY_AND_ASSIGN(GetChildProcessHostInfoTask); | |
2767 }; | |
2768 | 2759 |
2769 } // namespace | 2760 } // namespace |
2770 | 2761 |
2771 // Sample json input: { "command": "GetBrowserInfo" } | 2762 // Sample json input: { "command": "GetBrowserInfo" } |
2772 // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for | 2763 // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for |
2773 // sample json output. | 2764 // sample json output. |
2774 void TestingAutomationProvider::GetBrowserInfo( | 2765 void TestingAutomationProvider::GetBrowserInfo( |
2775 DictionaryValue* args, | 2766 DictionaryValue* args, |
2776 IPC::Message* reply_message) { | 2767 IPC::Message* reply_message) { |
2777 base::ThreadRestrictions::ScopedAllowIO allow_io; // needed for PathService | 2768 base::ThreadRestrictions::ScopedAllowIO allow_io; // needed for PathService |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2869 windows->Append(browser_item); | 2860 windows->Append(browser_item); |
2870 } | 2861 } |
2871 return_value->Set("windows", windows); | 2862 return_value->Set("windows", windows); |
2872 | 2863 |
2873 #if defined(OS_LINUX) | 2864 #if defined(OS_LINUX) |
2874 int flags = ChildProcessHost::CHILD_ALLOW_SELF; | 2865 int flags = ChildProcessHost::CHILD_ALLOW_SELF; |
2875 #else | 2866 #else |
2876 int flags = ChildProcessHost::CHILD_NORMAL; | 2867 int flags = ChildProcessHost::CHILD_NORMAL; |
2877 #endif | 2868 #endif |
2878 | 2869 |
2879 return_value->SetString("child_process_path", | |
2880 ChildProcessHost::GetChildPath(flags).value()); | |
2881 // Child processes are the processes for plugins and other workers. | |
2882 // Add all child processes in a list of dictionaries, one dictionary item | |
2883 // per child process. | |
2884 ListValue* child_processes = new ListValue; | |
2885 base::WaitableEvent event(true /* manual reset */, | |
2886 false /* not initially signaled */); | |
2887 CHECK(BrowserThread::PostTask( | |
2888 BrowserThread::IO, FROM_HERE, | |
2889 new GetChildProcessHostInfoTask(&event, child_processes))); | |
2890 event.Wait(); | |
2891 return_value->Set("child_processes", child_processes); | |
2892 | |
2893 // Add all extension processes in a list of dictionaries, one dictionary | 2870 // Add all extension processes in a list of dictionaries, one dictionary |
2894 // item per extension process. | 2871 // item per extension process. |
2895 ListValue* extension_views = new ListValue; | 2872 ListValue* extension_views = new ListValue; |
2896 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 2873 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
2897 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); | 2874 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); |
2898 for (size_t i = 0; i < profiles.size(); ++i) { | 2875 for (size_t i = 0; i < profiles.size(); ++i) { |
2899 ExtensionProcessManager* process_manager = | 2876 ExtensionProcessManager* process_manager = |
2900 profiles[i]->GetExtensionProcessManager(); | 2877 profiles[i]->GetExtensionProcessManager(); |
2901 if (!process_manager) | 2878 if (!process_manager) |
2902 continue; | 2879 continue; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2938 type = "unknown"; | 2915 type = "unknown"; |
2939 break; | 2916 break; |
2940 } | 2917 } |
2941 item->SetString("view_type", type); | 2918 item->SetString("view_type", type); |
2942 item->SetString("url", ex_host->GetURL().spec()); | 2919 item->SetString("url", ex_host->GetURL().spec()); |
2943 item->SetBoolean("loaded", ex_host->did_stop_loading()); | 2920 item->SetBoolean("loaded", ex_host->did_stop_loading()); |
2944 extension_views->Append(item); | 2921 extension_views->Append(item); |
2945 } | 2922 } |
2946 } | 2923 } |
2947 return_value->Set("extension_views", extension_views); | 2924 return_value->Set("extension_views", extension_views); |
2948 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | 2925 |
2926 return_value->SetString("child_process_path", | |
2927 ChildProcessHost::GetChildPath(flags).value()); | |
2928 // Child processes are the processes for plugins and other workers. | |
2929 // Add all child processes in a list of dictionaries, one dictionary item | |
2930 // per child process. | |
2931 ListValue* child_processes = new ListValue; | |
2932 return_value->Set("child_processes", child_processes); | |
2933 CHECK(BrowserThread::PostTaskAndReply( | |
Paweł Hajdan Jr.
2011/10/21 15:13:17
Why don't you just SendError if this fails?
| |
2934 BrowserThread::IO, FROM_HERE, | |
2935 base::Bind(&GetChildProcessHostInfo, child_processes), | |
2936 base::Bind(&AutomationJSONReply::SendSuccess, | |
2937 base::Owned(new AutomationJSONReply(this, reply_message)), | |
2938 base::Owned(return_value.release())))); | |
2949 } | 2939 } |
2950 | 2940 |
2951 // Sample json input: { "command": "GetProcessInfo" } | 2941 // Sample json input: { "command": "GetProcessInfo" } |
2952 // Refer to GetProcessInfo() in chrome/test/pyautolib/pyauto.py for | 2942 // Refer to GetProcessInfo() in chrome/test/pyautolib/pyauto.py for |
2953 // sample json output. | 2943 // sample json output. |
2954 void TestingAutomationProvider::GetProcessInfo( | 2944 void TestingAutomationProvider::GetProcessInfo( |
2955 DictionaryValue* args, | 2945 DictionaryValue* args, |
2956 IPC::Message* reply_message) { | 2946 IPC::Message* reply_message) { |
2957 scoped_refptr<ProcessInfoObserver> | 2947 scoped_refptr<ProcessInfoObserver> |
2958 proc_observer(new ProcessInfoObserver(this, reply_message)); | 2948 proc_observer(new ProcessInfoObserver(this, reply_message)); |
(...skipping 2905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5864 return; | 5854 return; |
5865 } | 5855 } |
5866 | 5856 |
5867 // This class will send the message immediately if no tab is loading. | 5857 // This class will send the message immediately if no tab is loading. |
5868 new AllTabsStoppedLoadingObserver(this, reply_message); | 5858 new AllTabsStoppedLoadingObserver(this, reply_message); |
5869 } | 5859 } |
5870 | 5860 |
5871 void TestingAutomationProvider::SetPolicies( | 5861 void TestingAutomationProvider::SetPolicies( |
5872 DictionaryValue* args, | 5862 DictionaryValue* args, |
5873 IPC::Message* reply_message) { | 5863 IPC::Message* reply_message) { |
5874 AutomationJSONReply reply(this, reply_message); | 5864 scoped_ptr<AutomationJSONReply> reply( |
5865 new AutomationJSONReply(this, reply_message)); | |
5875 | 5866 |
5876 #if !defined(ENABLE_CONFIGURATION_POLICY) || defined(OFFICIAL_BUILD) | 5867 #if !defined(ENABLE_CONFIGURATION_POLICY) || defined(OFFICIAL_BUILD) |
5877 reply.SendError("Configuration Policy disabled"); | 5868 reply->SendError("Configuration Policy disabled"); |
5878 #else | 5869 #else |
5879 const policy::PolicyDefinitionList* list = | 5870 const policy::PolicyDefinitionList* list = |
5880 policy::GetChromePolicyDefinitionList(); | 5871 policy::GetChromePolicyDefinitionList(); |
5881 policy::BrowserPolicyConnector* connector = | 5872 policy::BrowserPolicyConnector* connector = |
5882 g_browser_process->browser_policy_connector(); | 5873 g_browser_process->browser_policy_connector(); |
5883 struct { | 5874 struct { |
5884 std::string name; | 5875 std::string name; |
5885 policy::ConfigurationPolicyProvider* provider; | 5876 policy::ConfigurationPolicyProvider* provider; |
5886 } providers[] = { | 5877 } providers[] = { |
5887 { "managed_cloud", connector->GetManagedCloudProvider() }, | 5878 { "managed_cloud", connector->GetManagedCloudProvider() }, |
5888 { "managed_platform", connector->GetManagedPlatformProvider() }, | 5879 { "managed_platform", connector->GetManagedPlatformProvider() }, |
5889 { "recommended_cloud", connector->GetRecommendedCloudProvider() }, | 5880 { "recommended_cloud", connector->GetRecommendedCloudProvider() }, |
5890 { "recommended_platform", connector->GetRecommendedPlatformProvider() } | 5881 { "recommended_platform", connector->GetRecommendedPlatformProvider() } |
5891 }; | 5882 }; |
5892 // Verify if all the requested providers exist before changing anything. | 5883 // Verify if all the requested providers exist before changing anything. |
5893 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(providers); ++i) { | 5884 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(providers); ++i) { |
5894 DictionaryValue* policies = NULL; | 5885 DictionaryValue* policies = NULL; |
5895 if (args->GetDictionary(providers[i].name, &policies) && | 5886 if (args->GetDictionary(providers[i].name, &policies) && |
5896 policies && | 5887 policies && |
5897 !providers[i].provider) { | 5888 !providers[i].provider) { |
5898 reply.SendError("Provider not available: " + providers[i].name); | 5889 reply->SendError("Provider not available: " + providers[i].name); |
5899 return; | 5890 return; |
5900 } | 5891 } |
5901 } | 5892 } |
5902 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(providers); ++i) { | 5893 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(providers); ++i) { |
5903 DictionaryValue* policies = NULL; | 5894 DictionaryValue* policies = NULL; |
5904 if (args->GetDictionary(providers[i].name, &policies) && policies) { | 5895 if (args->GetDictionary(providers[i].name, &policies) && policies) { |
5905 policy::PolicyMap* map = new policy::PolicyMap; | 5896 policy::PolicyMap* map = new policy::PolicyMap; |
5906 map->LoadFrom(policies, list); | 5897 map->LoadFrom(policies, list); |
5907 providers[i].provider->OverridePolicies(map); | 5898 providers[i].provider->OverridePolicies(map); |
5908 } | 5899 } |
5909 } | 5900 } |
5910 | 5901 |
5911 reply.SendSuccess(NULL); | 5902 // OverridePolicies() triggers preference updates, which triggers preference |
5903 // listeners. Some policies (e.g. URLBlacklist) post tasks to other message | |
5904 // loops before they start being enforced; make sure those tasks have | |
5905 // finished. | |
5906 PostTask(BrowserThread::IO, | |
Paweł Hajdan Jr.
2011/10/21 15:13:17
Please add some base::Bind gurus for possible advi
Joao da Silva
2011/10/21 16:25:53
Good idea, adding @willchan as the Bind guru :-)
willchan no longer on Chromium
2011/10/21 20:50:29
This code gave me a good chuckle today. Thanks for
Joao da Silva
2011/10/22 11:26:50
Thanks for taking a look. I've added an explicit c
| |
5907 base::Bind(&PostTask, BrowserThread::FILE, | |
5908 base::Bind(&PostTask, BrowserThread::IO, | |
5909 base::Bind(&PostTask, BrowserThread::UI, | |
Paweł Hajdan Jr.
2011/10/21 15:13:17
So it seems you've done the CHECK in PostTask beca
Joao da Silva
2011/10/21 16:25:53
I think replies have to be sent from UI; please co
| |
5910 base::Bind(&AutomationJSONReply::SendSuccess, | |
5911 base::Owned(reply.release()), | |
5912 static_cast<const Value*>(NULL)))))); | |
5912 #endif // defined(OFFICIAL_BUILD) | 5913 #endif // defined(OFFICIAL_BUILD) |
5913 } | 5914 } |
5914 | 5915 |
5915 void TestingAutomationProvider::GetPolicyDefinitionList( | 5916 void TestingAutomationProvider::GetPolicyDefinitionList( |
5916 DictionaryValue* args, | 5917 DictionaryValue* args, |
5917 IPC::Message* reply_message) { | 5918 IPC::Message* reply_message) { |
5918 AutomationJSONReply reply(this, reply_message); | 5919 AutomationJSONReply reply(this, reply_message); |
5919 | 5920 |
5920 #if !defined(ENABLE_CONFIGURATION_POLICY) | 5921 #if !defined(ENABLE_CONFIGURATION_POLICY) |
5921 reply.SendError("Configuration Policy disabled"); | 5922 reply.SendError("Configuration Policy disabled"); |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6535 | 6536 |
6536 Send(reply_message_); | 6537 Send(reply_message_); |
6537 redirect_query_ = 0; | 6538 redirect_query_ = 0; |
6538 reply_message_ = NULL; | 6539 reply_message_ = NULL; |
6539 } | 6540 } |
6540 | 6541 |
6541 void TestingAutomationProvider::OnRemoveProvider() { | 6542 void TestingAutomationProvider::OnRemoveProvider() { |
6542 if (g_browser_process) | 6543 if (g_browser_process) |
6543 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6544 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6544 } | 6545 } |
OLD | NEW |