| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 4826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4837 } | 4837 } |
| 4838 if (!sync_waiter_->IsSyncAlreadySetup()) { | 4838 if (!sync_waiter_->IsSyncAlreadySetup()) { |
| 4839 sync_info->SetString("summary", "SYNC DISABLED"); | 4839 sync_info->SetString("summary", "SYNC DISABLED"); |
| 4840 } else { | 4840 } else { |
| 4841 ProfileSyncService* service = sync_waiter_->service(); | 4841 ProfileSyncService* service = sync_waiter_->service(); |
| 4842 ProfileSyncService::Status status = sync_waiter_->GetStatus(); | 4842 ProfileSyncService::Status status = sync_waiter_->GetStatus(); |
| 4843 sync_info->SetString("sync url", service->sync_service_url().host()); | 4843 sync_info->SetString("sync url", service->sync_service_url().host()); |
| 4844 sync_info->SetString("last synced", service->GetLastSyncedTimeString()); | 4844 sync_info->SetString("last synced", service->GetLastSyncedTimeString()); |
| 4845 sync_info->SetInteger("updates received", status.updates_received); | 4845 sync_info->SetInteger("updates received", status.updates_received); |
| 4846 ListValue* synced_datatype_list = new ListValue; | 4846 ListValue* synced_datatype_list = new ListValue; |
| 4847 const syncable::ModelTypeSet synced_datatypes = | 4847 const syncer::ModelTypeSet synced_datatypes = |
| 4848 service->GetPreferredDataTypes(); | 4848 service->GetPreferredDataTypes(); |
| 4849 for (syncable::ModelTypeSet::Iterator it = synced_datatypes.First(); | 4849 for (syncer::ModelTypeSet::Iterator it = synced_datatypes.First(); |
| 4850 it.Good(); it.Inc()) { | 4850 it.Good(); it.Inc()) { |
| 4851 synced_datatype_list->Append( | 4851 synced_datatype_list->Append( |
| 4852 new StringValue(syncable::ModelTypeToString(it.Get()))); | 4852 new StringValue(syncer::ModelTypeToString(it.Get()))); |
| 4853 } | 4853 } |
| 4854 sync_info->Set("synced datatypes", synced_datatype_list); | 4854 sync_info->Set("synced datatypes", synced_datatype_list); |
| 4855 } | 4855 } |
| 4856 return_value->Set("sync_info", sync_info); | 4856 return_value->Set("sync_info", sync_info); |
| 4857 reply.SendSuccess(return_value.get()); | 4857 reply.SendSuccess(return_value.get()); |
| 4858 } | 4858 } |
| 4859 | 4859 |
| 4860 // Sample json output: { "success": true } | 4860 // Sample json output: { "success": true } |
| 4861 void TestingAutomationProvider::AwaitFullSyncCompletion( | 4861 void TestingAutomationProvider::AwaitFullSyncCompletion( |
| 4862 Browser* browser, | 4862 Browser* browser, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4943 } | 4943 } |
| 4944 std::string first_datatype; | 4944 std::string first_datatype; |
| 4945 datatypes->GetString(0, &first_datatype); | 4945 datatypes->GetString(0, &first_datatype); |
| 4946 if (first_datatype == "All") { | 4946 if (first_datatype == "All") { |
| 4947 sync_waiter_->EnableSyncForAllDatatypes(); | 4947 sync_waiter_->EnableSyncForAllDatatypes(); |
| 4948 } else { | 4948 } else { |
| 4949 int num_datatypes = datatypes->GetSize(); | 4949 int num_datatypes = datatypes->GetSize(); |
| 4950 for (int i = 0; i < num_datatypes; ++i) { | 4950 for (int i = 0; i < num_datatypes; ++i) { |
| 4951 std::string datatype_string; | 4951 std::string datatype_string; |
| 4952 datatypes->GetString(i, &datatype_string); | 4952 datatypes->GetString(i, &datatype_string); |
| 4953 syncable::ModelType datatype = | 4953 syncer::ModelType datatype = |
| 4954 syncable::ModelTypeFromString(datatype_string); | 4954 syncer::ModelTypeFromString(datatype_string); |
| 4955 if (datatype == syncable::UNSPECIFIED) { | 4955 if (datatype == syncer::UNSPECIFIED) { |
| 4956 AutomationJSONReply(this, reply_message).SendError(StringPrintf( | 4956 AutomationJSONReply(this, reply_message).SendError(StringPrintf( |
| 4957 "Invalid datatype string: %s.", datatype_string.c_str())); | 4957 "Invalid datatype string: %s.", datatype_string.c_str())); |
| 4958 return; | 4958 return; |
| 4959 } | 4959 } |
| 4960 sync_waiter_->EnableSyncForDatatype(datatype); | 4960 sync_waiter_->EnableSyncForDatatype(datatype); |
| 4961 sync_waiter_->AwaitFullSyncCompletion(StringPrintf( | 4961 sync_waiter_->AwaitFullSyncCompletion(StringPrintf( |
| 4962 "Enabling datatype: %s", datatype_string.c_str())); | 4962 "Enabling datatype: %s", datatype_string.c_str())); |
| 4963 } | 4963 } |
| 4964 } | 4964 } |
| 4965 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 4965 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 4992 reply.SendError("Invalid or missing string"); | 4992 reply.SendError("Invalid or missing string"); |
| 4993 return; | 4993 return; |
| 4994 } | 4994 } |
| 4995 if (first_datatype == "All") { | 4995 if (first_datatype == "All") { |
| 4996 sync_waiter_->DisableSyncForAllDatatypes(); | 4996 sync_waiter_->DisableSyncForAllDatatypes(); |
| 4997 } else { | 4997 } else { |
| 4998 int num_datatypes = datatypes->GetSize(); | 4998 int num_datatypes = datatypes->GetSize(); |
| 4999 for (int i = 0; i < num_datatypes; i++) { | 4999 for (int i = 0; i < num_datatypes; i++) { |
| 5000 std::string datatype_string; | 5000 std::string datatype_string; |
| 5001 datatypes->GetString(i, &datatype_string); | 5001 datatypes->GetString(i, &datatype_string); |
| 5002 syncable::ModelType datatype = | 5002 syncer::ModelType datatype = |
| 5003 syncable::ModelTypeFromString(datatype_string); | 5003 syncer::ModelTypeFromString(datatype_string); |
| 5004 if (datatype == syncable::UNSPECIFIED) { | 5004 if (datatype == syncer::UNSPECIFIED) { |
| 5005 AutomationJSONReply(this, reply_message).SendError(StringPrintf( | 5005 AutomationJSONReply(this, reply_message).SendError(StringPrintf( |
| 5006 "Invalid datatype string: %s.", datatype_string.c_str())); | 5006 "Invalid datatype string: %s.", datatype_string.c_str())); |
| 5007 return; | 5007 return; |
| 5008 } | 5008 } |
| 5009 sync_waiter_->DisableSyncForDatatype(datatype); | 5009 sync_waiter_->DisableSyncForDatatype(datatype); |
| 5010 sync_waiter_->AwaitFullSyncCompletion(StringPrintf( | 5010 sync_waiter_->AwaitFullSyncCompletion(StringPrintf( |
| 5011 "Disabling datatype: %s", datatype_string.c_str())); | 5011 "Disabling datatype: %s", datatype_string.c_str())); |
| 5012 } | 5012 } |
| 5013 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 5013 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 5014 return_value->SetBoolean("success", true); | 5014 return_value->SetBoolean("success", true); |
| (...skipping 1752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6767 void TestingAutomationProvider::OnRemoveProvider() { | 6767 void TestingAutomationProvider::OnRemoveProvider() { |
| 6768 if (g_browser_process) | 6768 if (g_browser_process) |
| 6769 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6769 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
| 6770 } | 6770 } |
| 6771 | 6771 |
| 6772 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 6772 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
| 6773 WebContents* tab) { | 6773 WebContents* tab) { |
| 6774 if (chrome::GetActiveWebContents(browser) != tab) | 6774 if (chrome::GetActiveWebContents(browser) != tab) |
| 6775 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); | 6775 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); |
| 6776 } | 6776 } |
| OLD | NEW |