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 2483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2494 browser_handler_map["GetActiveNotifications"] = | 2494 browser_handler_map["GetActiveNotifications"] = |
2495 &TestingAutomationProvider::GetActiveNotifications; | 2495 &TestingAutomationProvider::GetActiveNotifications; |
2496 browser_handler_map["CloseNotification"] = | 2496 browser_handler_map["CloseNotification"] = |
2497 &TestingAutomationProvider::CloseNotification; | 2497 &TestingAutomationProvider::CloseNotification; |
2498 browser_handler_map["WaitForNotificationCount"] = | 2498 browser_handler_map["WaitForNotificationCount"] = |
2499 &TestingAutomationProvider::WaitForNotificationCount; | 2499 &TestingAutomationProvider::WaitForNotificationCount; |
2500 | 2500 |
2501 browser_handler_map["SignInToSync"] = | 2501 browser_handler_map["SignInToSync"] = |
2502 &TestingAutomationProvider::SignInToSync; | 2502 &TestingAutomationProvider::SignInToSync; |
2503 browser_handler_map["GetSyncInfo"] = &TestingAutomationProvider::GetSyncInfo; | 2503 browser_handler_map["GetSyncInfo"] = &TestingAutomationProvider::GetSyncInfo; |
2504 browser_handler_map["AwaitSyncCycleCompletion"] = | 2504 browser_handler_map["AwaitFullSyncCompletion"] = |
2505 &TestingAutomationProvider::AwaitSyncCycleCompletion; | 2505 &TestingAutomationProvider::AwaitFullSyncCompletion; |
2506 browser_handler_map["AwaitSyncRestart"] = | 2506 browser_handler_map["AwaitSyncRestart"] = |
2507 &TestingAutomationProvider::AwaitSyncRestart; | 2507 &TestingAutomationProvider::AwaitSyncRestart; |
2508 browser_handler_map["EnableSyncForDatatypes"] = | 2508 browser_handler_map["EnableSyncForDatatypes"] = |
2509 &TestingAutomationProvider::EnableSyncForDatatypes; | 2509 &TestingAutomationProvider::EnableSyncForDatatypes; |
2510 browser_handler_map["DisableSyncForDatatypes"] = | 2510 browser_handler_map["DisableSyncForDatatypes"] = |
2511 &TestingAutomationProvider::DisableSyncForDatatypes; | 2511 &TestingAutomationProvider::DisableSyncForDatatypes; |
2512 | 2512 |
2513 browser_handler_map["GetNTPInfo"] = | 2513 browser_handler_map["GetNTPInfo"] = |
2514 &TestingAutomationProvider::GetNTPInfo; | 2514 &TestingAutomationProvider::GetNTPInfo; |
2515 browser_handler_map["MoveNTPMostVisitedThumbnail"] = | 2515 browser_handler_map["MoveNTPMostVisitedThumbnail"] = |
(...skipping 2266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4782 synced_datatype_list->Append( | 4782 synced_datatype_list->Append( |
4783 new StringValue(syncable::ModelTypeToString(*it))); | 4783 new StringValue(syncable::ModelTypeToString(*it))); |
4784 } | 4784 } |
4785 sync_info->Set("synced datatypes", synced_datatype_list); | 4785 sync_info->Set("synced datatypes", synced_datatype_list); |
4786 } | 4786 } |
4787 return_value->Set("sync_info", sync_info); | 4787 return_value->Set("sync_info", sync_info); |
4788 reply.SendSuccess(return_value.get()); | 4788 reply.SendSuccess(return_value.get()); |
4789 } | 4789 } |
4790 | 4790 |
4791 // Sample json output: { "success": true } | 4791 // Sample json output: { "success": true } |
4792 void TestingAutomationProvider::AwaitSyncCycleCompletion( | 4792 void TestingAutomationProvider::AwaitFullSyncCompletion( |
4793 Browser* browser, | 4793 Browser* browser, |
4794 DictionaryValue* args, | 4794 DictionaryValue* args, |
4795 IPC::Message* reply_message) { | 4795 IPC::Message* reply_message) { |
4796 AutomationJSONReply reply(this, reply_message); | 4796 AutomationJSONReply reply(this, reply_message); |
4797 if (sync_waiter_.get() == NULL) { | 4797 if (sync_waiter_.get() == NULL) { |
4798 sync_waiter_.reset( | 4798 sync_waiter_.reset( |
4799 ProfileSyncServiceHarness::CreateAndAttach(browser->profile())); | 4799 ProfileSyncServiceHarness::CreateAndAttach(browser->profile())); |
4800 } | 4800 } |
4801 if (!sync_waiter_->IsSyncAlreadySetup()) { | 4801 if (!sync_waiter_->IsSyncAlreadySetup()) { |
4802 reply.SendError("Not signed in to sync"); | 4802 reply.SendError("Not signed in to sync"); |
4803 return; | 4803 return; |
4804 } | 4804 } |
4805 // Ensure that the profile sync service and sync backend host are initialized | 4805 // Ensure that the profile sync service and sync backend host are initialized |
4806 // before waiting for sync cycle completion. In cases where the browser is | 4806 // before waiting for sync cycle completion. In cases where the browser is |
4807 // restarted with sync enabled, these operations may still be in flight. | 4807 // restarted with sync enabled, these operations may still be in flight. |
4808 if (!browser->profile()->GetProfileSyncService()) { | 4808 if (!browser->profile()->GetProfileSyncService()) { |
4809 reply.SendError("ProfileSyncService initialization failed."); | 4809 reply.SendError("ProfileSyncService initialization failed."); |
4810 return; | 4810 return; |
4811 } | 4811 } |
4812 if (!sync_waiter_->service()->sync_initialized() && | 4812 if (!sync_waiter_->service()->sync_initialized() && |
4813 !sync_waiter_->AwaitBackendInitialized()) { | 4813 !sync_waiter_->AwaitBackendInitialized()) { |
4814 reply.SendError("Sync backend host initialization failed."); | 4814 reply.SendError("Sync backend host initialization failed."); |
4815 return; | 4815 return; |
4816 } | 4816 } |
4817 if (!sync_waiter_->AwaitSyncCycleCompletion("Waiting for sync cycle")) { | 4817 if (!sync_waiter_->AwaitFullSyncCompletion("Waiting for sync cycle")) { |
4818 reply.SendError("Sync cycle did not complete."); | 4818 reply.SendError("Sync cycle did not complete."); |
4819 return; | 4819 return; |
4820 } | 4820 } |
4821 ProfileSyncService::Status status = sync_waiter_->GetStatus(); | 4821 ProfileSyncService::Status status = sync_waiter_->GetStatus(); |
4822 if (status.summary == ProfileSyncService::Status::READY) { | 4822 if (status.summary == ProfileSyncService::Status::READY) { |
4823 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 4823 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
4824 return_value->SetBoolean("success", true); | 4824 return_value->SetBoolean("success", true); |
4825 reply.SendSuccess(return_value.get()); | 4825 reply.SendSuccess(return_value.get()); |
4826 } else { | 4826 } else { |
4827 std::string error_msg = "Wait for sync cycle was unsuccessful. " | 4827 std::string error_msg = "Wait for sync cycle was unsuccessful. " |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4898 std::string datatype_string; | 4898 std::string datatype_string; |
4899 datatypes->GetString(i, &datatype_string); | 4899 datatypes->GetString(i, &datatype_string); |
4900 syncable::ModelType datatype = | 4900 syncable::ModelType datatype = |
4901 syncable::ModelTypeFromString(datatype_string); | 4901 syncable::ModelTypeFromString(datatype_string); |
4902 if (datatype == syncable::UNSPECIFIED) { | 4902 if (datatype == syncable::UNSPECIFIED) { |
4903 AutomationJSONReply(this, reply_message).SendError(StringPrintf( | 4903 AutomationJSONReply(this, reply_message).SendError(StringPrintf( |
4904 "Invalid datatype string: %s.", datatype_string.c_str())); | 4904 "Invalid datatype string: %s.", datatype_string.c_str())); |
4905 return; | 4905 return; |
4906 } | 4906 } |
4907 sync_waiter_->EnableSyncForDatatype(datatype); | 4907 sync_waiter_->EnableSyncForDatatype(datatype); |
4908 sync_waiter_->AwaitSyncCycleCompletion(StringPrintf( | 4908 sync_waiter_->AwaitFullSyncCompletion(StringPrintf( |
4909 "Enabling datatype: %s", datatype_string.c_str())); | 4909 "Enabling datatype: %s", datatype_string.c_str())); |
4910 } | 4910 } |
4911 } | 4911 } |
4912 ProfileSyncService::Status status = sync_waiter_->GetStatus(); | 4912 ProfileSyncService::Status status = sync_waiter_->GetStatus(); |
4913 if (status.summary == ProfileSyncService::Status::READY || | 4913 if (status.summary == ProfileSyncService::Status::READY || |
4914 status.summary == ProfileSyncService::Status::SYNCING) { | 4914 status.summary == ProfileSyncService::Status::SYNCING) { |
4915 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 4915 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
4916 return_value->SetBoolean("success", true); | 4916 return_value->SetBoolean("success", true); |
4917 reply.SendSuccess(return_value.get()); | 4917 reply.SendSuccess(return_value.get()); |
4918 } else { | 4918 } else { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4962 std::string datatype_string; | 4962 std::string datatype_string; |
4963 datatypes->GetString(i, &datatype_string); | 4963 datatypes->GetString(i, &datatype_string); |
4964 syncable::ModelType datatype = | 4964 syncable::ModelType datatype = |
4965 syncable::ModelTypeFromString(datatype_string); | 4965 syncable::ModelTypeFromString(datatype_string); |
4966 if (datatype == syncable::UNSPECIFIED) { | 4966 if (datatype == syncable::UNSPECIFIED) { |
4967 AutomationJSONReply(this, reply_message).SendError(StringPrintf( | 4967 AutomationJSONReply(this, reply_message).SendError(StringPrintf( |
4968 "Invalid datatype string: %s.", datatype_string.c_str())); | 4968 "Invalid datatype string: %s.", datatype_string.c_str())); |
4969 return; | 4969 return; |
4970 } | 4970 } |
4971 sync_waiter_->DisableSyncForDatatype(datatype); | 4971 sync_waiter_->DisableSyncForDatatype(datatype); |
4972 sync_waiter_->AwaitSyncCycleCompletion(StringPrintf( | 4972 sync_waiter_->AwaitFullSyncCompletion(StringPrintf( |
4973 "Disabling datatype: %s", datatype_string.c_str())); | 4973 "Disabling datatype: %s", datatype_string.c_str())); |
4974 } | 4974 } |
4975 ProfileSyncService::Status status = sync_waiter_->GetStatus(); | 4975 ProfileSyncService::Status status = sync_waiter_->GetStatus(); |
4976 if (status.summary == ProfileSyncService::Status::READY || | 4976 if (status.summary == ProfileSyncService::Status::READY || |
4977 status.summary == ProfileSyncService::Status::SYNCING) { | 4977 status.summary == ProfileSyncService::Status::SYNCING) { |
4978 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 4978 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
4979 return_value->SetBoolean("success", true); | 4979 return_value->SetBoolean("success", true); |
4980 reply.SendSuccess(return_value.get()); | 4980 reply.SendSuccess(return_value.get()); |
4981 } else { | 4981 } else { |
4982 reply.SendError("Disabling sync for given datatypes was unsuccessful"); | 4982 reply.SendError("Disabling sync for given datatypes was unsuccessful"); |
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6491 | 6491 |
6492 Send(reply_message_); | 6492 Send(reply_message_); |
6493 redirect_query_ = 0; | 6493 redirect_query_ = 0; |
6494 reply_message_ = NULL; | 6494 reply_message_ = NULL; |
6495 } | 6495 } |
6496 | 6496 |
6497 void TestingAutomationProvider::OnRemoveProvider() { | 6497 void TestingAutomationProvider::OnRemoveProvider() { |
6498 if (g_browser_process) | 6498 if (g_browser_process) |
6499 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6499 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6500 } | 6500 } |
OLD | NEW |