Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
| 16 #include "base/json/json_reader.h" | 16 #include "base/json/json_reader.h" |
| 17 #include "base/json/json_writer.h" | 17 #include "base/json/json_writer.h" |
| 18 #include "base/json/string_escape.h" | 18 #include "base/json/string_escape.h" |
| 19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 20 #include "base/process.h" | 20 #include "base/process.h" |
| 21 #include "base/process_util.h" | 21 #include "base/process_util.h" |
| 22 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
| 23 #include "base/synchronization/waitable_event.h" | |
| 23 #include "base/threading/thread_restrictions.h" | 24 #include "base/threading/thread_restrictions.h" |
| 24 #include "base/time.h" | 25 #include "base/time.h" |
| 25 #include "base/utf_string_conversions.h" | 26 #include "base/utf_string_conversions.h" |
| 26 #include "chrome/app/chrome_command_ids.h" | 27 #include "chrome/app/chrome_command_ids.h" |
| 27 #include "chrome/browser/autocomplete/autocomplete.h" | 28 #include "chrome/browser/autocomplete/autocomplete.h" |
| 28 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 29 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 29 #include "chrome/browser/autocomplete/autocomplete_match.h" | 30 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 30 #include "chrome/browser/autofill/autofill_manager.h" | 31 #include "chrome/browser/autofill/autofill_manager.h" |
| 31 #include "chrome/browser/autofill/credit_card.h" | 32 #include "chrome/browser/autofill/credit_card.h" |
| 32 #include "chrome/browser/autofill/personal_data_manager.h" | 33 #include "chrome/browser/autofill/personal_data_manager.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 } | 170 } |
| 170 | 171 |
| 171 virtual std::string GetHTMLContents() { return contents_; } | 172 virtual std::string GetHTMLContents() { return contents_; } |
| 172 | 173 |
| 173 private: | 174 private: |
| 174 const std::string contents_; | 175 const std::string contents_; |
| 175 | 176 |
| 176 DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); | 177 DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); |
| 177 }; | 178 }; |
| 178 | 179 |
| 180 void WaitForPendingTasksOn(BrowserThread::ID identifier) { | |
| 181 CHECK(!BrowserThread::CurrentlyOn(identifier)); | |
|
Paweł Hajdan Jr.
2011/10/18 10:30:45
I commented about those lines. Please apply that c
| |
| 182 base::WaitableEvent event(true, // manual reset | |
| 183 false); // not initially signaled | |
| 184 CHECK(BrowserThread::PostTask( | |
| 185 identifier, | |
| 186 FROM_HERE, | |
| 187 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event)))); | |
| 188 event.Wait(); | |
| 189 } | |
| 190 | |
| 179 } // namespace | 191 } // namespace |
| 180 | 192 |
| 181 TestingAutomationProvider::TestingAutomationProvider(Profile* profile) | 193 TestingAutomationProvider::TestingAutomationProvider(Profile* profile) |
| 182 : AutomationProvider(profile), | 194 : AutomationProvider(profile), |
| 183 #if defined(TOOLKIT_VIEWS) | 195 #if defined(TOOLKIT_VIEWS) |
| 184 popup_menu_waiter_(NULL), | 196 popup_menu_waiter_(NULL), |
| 185 #endif | 197 #endif |
| 186 redirect_query_(0) { | 198 redirect_query_(0) { |
| 187 BrowserList::AddObserver(this); | 199 BrowserList::AddObserver(this); |
| 188 registrar_.Add(this, chrome::NOTIFICATION_SESSION_END, | 200 registrar_.Add(this, chrome::NOTIFICATION_SESSION_END, |
| (...skipping 2538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2727 reply.SendError("Invalid action"); | 2739 reply.SendError("Invalid action"); |
| 2728 } | 2740 } |
| 2729 | 2741 |
| 2730 namespace { | 2742 namespace { |
| 2731 | 2743 |
| 2732 // Task to get info about BrowserChildProcessHost. Must run on IO thread to | 2744 // Task to get info about BrowserChildProcessHost. Must run on IO thread to |
| 2733 // honor the semantics of BrowserChildProcessHost. | 2745 // honor the semantics of BrowserChildProcessHost. |
| 2734 // Used by AutomationProvider::GetBrowserInfo(). | 2746 // Used by AutomationProvider::GetBrowserInfo(). |
| 2735 class GetChildProcessHostInfoTask : public Task { | 2747 class GetChildProcessHostInfoTask : public Task { |
| 2736 public: | 2748 public: |
| 2737 GetChildProcessHostInfoTask(base::WaitableEvent* event, | 2749 explicit GetChildProcessHostInfoTask(ListValue* child_processes) |
| 2738 ListValue* child_processes) | 2750 : child_processes_(child_processes) {} |
| 2739 : event_(event), | |
| 2740 child_processes_(child_processes) {} | |
| 2741 | 2751 |
| 2742 virtual void Run() { | 2752 virtual void Run() OVERRIDE { |
| 2743 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2753 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2744 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { | 2754 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { |
| 2745 // Only add processes which are already started, | 2755 // Only add processes which are already started, |
| 2746 // since we need their handle. | 2756 // since we need their handle. |
| 2747 if ((*iter)->handle() == base::kNullProcessHandle) { | 2757 if ((*iter)->handle() == base::kNullProcessHandle) { |
| 2748 continue; | 2758 continue; |
| 2749 } | 2759 } |
| 2750 ChildProcessInfo* info = *iter; | 2760 ChildProcessInfo* info = *iter; |
| 2751 DictionaryValue* item = new DictionaryValue; | 2761 DictionaryValue* item = new DictionaryValue; |
| 2752 item->SetString("name", info->name()); | 2762 item->SetString("name", info->name()); |
| 2753 item->SetString("type", | 2763 item->SetString("type", |
| 2754 ChildProcessInfo::GetTypeNameInEnglish(info->type())); | 2764 ChildProcessInfo::GetTypeNameInEnglish(info->type())); |
| 2755 item->SetInteger("pid", base::GetProcId(info->handle())); | 2765 item->SetInteger("pid", base::GetProcId(info->handle())); |
| 2756 child_processes_->Append(item); | 2766 child_processes_->Append(item); |
| 2757 } | 2767 } |
| 2758 event_->Signal(); | |
| 2759 } | 2768 } |
| 2760 | 2769 |
| 2761 private: | 2770 private: |
| 2762 base::WaitableEvent* const event_; // weak | |
| 2763 ListValue* child_processes_; | 2771 ListValue* child_processes_; |
| 2764 | 2772 |
| 2765 DISALLOW_COPY_AND_ASSIGN(GetChildProcessHostInfoTask); | 2773 DISALLOW_COPY_AND_ASSIGN(GetChildProcessHostInfoTask); |
| 2766 }; | 2774 }; |
| 2767 | 2775 |
| 2768 } // namespace | 2776 } // namespace |
| 2769 | 2777 |
| 2770 // Sample json input: { "command": "GetBrowserInfo" } | 2778 // Sample json input: { "command": "GetBrowserInfo" } |
| 2771 // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for | 2779 // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for |
| 2772 // sample json output. | 2780 // sample json output. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2874 #else | 2882 #else |
| 2875 int flags = ChildProcessHost::CHILD_NORMAL; | 2883 int flags = ChildProcessHost::CHILD_NORMAL; |
| 2876 #endif | 2884 #endif |
| 2877 | 2885 |
| 2878 return_value->SetString("child_process_path", | 2886 return_value->SetString("child_process_path", |
| 2879 ChildProcessHost::GetChildPath(flags).value()); | 2887 ChildProcessHost::GetChildPath(flags).value()); |
| 2880 // Child processes are the processes for plugins and other workers. | 2888 // Child processes are the processes for plugins and other workers. |
| 2881 // Add all child processes in a list of dictionaries, one dictionary item | 2889 // Add all child processes in a list of dictionaries, one dictionary item |
| 2882 // per child process. | 2890 // per child process. |
| 2883 ListValue* child_processes = new ListValue; | 2891 ListValue* child_processes = new ListValue; |
| 2884 base::WaitableEvent event(true /* manual reset */, | |
| 2885 false /* not initially signaled */); | |
| 2886 CHECK(BrowserThread::PostTask( | 2892 CHECK(BrowserThread::PostTask( |
| 2887 BrowserThread::IO, FROM_HERE, | 2893 BrowserThread::IO, FROM_HERE, |
| 2888 new GetChildProcessHostInfoTask(&event, child_processes))); | 2894 new GetChildProcessHostInfoTask(child_processes))); |
| 2889 event.Wait(); | 2895 WaitForPendingTasksOn(BrowserThread::IO); |
| 2890 return_value->Set("child_processes", child_processes); | 2896 return_value->Set("child_processes", child_processes); |
| 2891 | 2897 |
| 2892 // Add all extension processes in a list of dictionaries, one dictionary | 2898 // Add all extension processes in a list of dictionaries, one dictionary |
| 2893 // item per extension process. | 2899 // item per extension process. |
| 2894 ListValue* extension_views = new ListValue; | 2900 ListValue* extension_views = new ListValue; |
| 2895 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 2901 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 2896 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); | 2902 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); |
| 2897 for (size_t i = 0; i < profiles.size(); ++i) { | 2903 for (size_t i = 0; i < profiles.size(); ++i) { |
| 2898 ExtensionProcessManager* process_manager = | 2904 ExtensionProcessManager* process_manager = |
| 2899 profiles[i]->GetExtensionProcessManager(); | 2905 profiles[i]->GetExtensionProcessManager(); |
| (...skipping 2994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5894 } | 5900 } |
| 5895 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(providers); ++i) { | 5901 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(providers); ++i) { |
| 5896 DictionaryValue* policies = NULL; | 5902 DictionaryValue* policies = NULL; |
| 5897 if (args->GetDictionary(providers[i].name, &policies) && policies) { | 5903 if (args->GetDictionary(providers[i].name, &policies) && policies) { |
| 5898 policy::PolicyMap* map = new policy::PolicyMap; | 5904 policy::PolicyMap* map = new policy::PolicyMap; |
| 5899 map->LoadFrom(policies, list); | 5905 map->LoadFrom(policies, list); |
| 5900 providers[i].provider->OverridePolicies(map); | 5906 providers[i].provider->OverridePolicies(map); |
| 5901 } | 5907 } |
| 5902 } | 5908 } |
| 5903 | 5909 |
| 5910 // OverridePolicies() triggers preference updates, which triggers preference | |
| 5911 // listeners. Some policies (e.g. URLBlacklist) post tasks to other message | |
| 5912 // loops before they start being enforced; make sure those tasks have | |
| 5913 // finished. | |
| 5914 WaitForPendingTasksOn(BrowserThread::IO); | |
| 5915 WaitForPendingTasksOn(BrowserThread::FILE); | |
| 5916 WaitForPendingTasksOn(BrowserThread::IO); | |
| 5917 | |
| 5904 reply.SendSuccess(NULL); | 5918 reply.SendSuccess(NULL); |
| 5905 #endif // defined(OFFICIAL_BUILD) | 5919 #endif // defined(OFFICIAL_BUILD) |
| 5906 } | 5920 } |
| 5907 | 5921 |
| 5908 void TestingAutomationProvider::GetPolicyDefinitionList( | 5922 void TestingAutomationProvider::GetPolicyDefinitionList( |
| 5909 DictionaryValue* args, | 5923 DictionaryValue* args, |
| 5910 IPC::Message* reply_message) { | 5924 IPC::Message* reply_message) { |
| 5911 AutomationJSONReply reply(this, reply_message); | 5925 AutomationJSONReply reply(this, reply_message); |
| 5912 | 5926 |
| 5913 #if !defined(ENABLE_CONFIGURATION_POLICY) | 5927 #if !defined(ENABLE_CONFIGURATION_POLICY) |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6528 | 6542 |
| 6529 Send(reply_message_); | 6543 Send(reply_message_); |
| 6530 redirect_query_ = 0; | 6544 redirect_query_ = 0; |
| 6531 reply_message_ = NULL; | 6545 reply_message_ = NULL; |
| 6532 } | 6546 } |
| 6533 | 6547 |
| 6534 void TestingAutomationProvider::OnRemoveProvider() { | 6548 void TestingAutomationProvider::OnRemoveProvider() { |
| 6535 if (g_browser_process) | 6549 if (g_browser_process) |
| 6536 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6550 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
| 6537 } | 6551 } |
| OLD | NEW |