| 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 "extensions/browser/api/management/management_api.h" | 5 #include "extensions/browser/api/management/management_api.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 20 #include "base/stl_util.h" |
| 20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
| 24 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 25 #include "content/public/browser/browser_context.h" | 26 #include "content/public/browser/browser_context.h" |
| 26 #include "extensions/browser/api/extensions_api_client.h" | 27 #include "extensions/browser/api/extensions_api_client.h" |
| 27 #include "extensions/browser/api/management/management_api_constants.h" | 28 #include "extensions/browser/api/management/management_api_constants.h" |
| 28 #include "extensions/browser/event_router.h" | 29 #include "extensions/browser/event_router.h" |
| 29 #include "extensions/browser/extension_prefs.h" | 30 #include "extensions/browser/extension_prefs.h" |
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 if (!extension) | 700 if (!extension) |
| 700 return RespondNow(Error(keys::kNoExtensionError, params->id)); | 701 return RespondNow(Error(keys::kNoExtensionError, params->id)); |
| 701 | 702 |
| 702 if (!extension->is_app()) | 703 if (!extension->is_app()) |
| 703 return RespondNow(Error(keys::kNotAnAppError, params->id)); | 704 return RespondNow(Error(keys::kNotAnAppError, params->id)); |
| 704 | 705 |
| 705 std::vector<management::LaunchType> available_launch_types = | 706 std::vector<management::LaunchType> available_launch_types = |
| 706 GetAvailableLaunchTypes(*extension, delegate); | 707 GetAvailableLaunchTypes(*extension, delegate); |
| 707 | 708 |
| 708 management::LaunchType app_launch_type = params->launch_type; | 709 management::LaunchType app_launch_type = params->launch_type; |
| 709 if (std::find(available_launch_types.begin(), available_launch_types.end(), | 710 if (!base::ContainsValue(available_launch_types, app_launch_type)) { |
| 710 app_launch_type) == available_launch_types.end()) { | |
| 711 return RespondNow(Error(keys::kLaunchTypeNotAvailableError)); | 711 return RespondNow(Error(keys::kLaunchTypeNotAvailableError)); |
| 712 } | 712 } |
| 713 | 713 |
| 714 LaunchType launch_type = LAUNCH_TYPE_DEFAULT; | 714 LaunchType launch_type = LAUNCH_TYPE_DEFAULT; |
| 715 switch (app_launch_type) { | 715 switch (app_launch_type) { |
| 716 case management::LAUNCH_TYPE_OPEN_AS_PINNED_TAB: | 716 case management::LAUNCH_TYPE_OPEN_AS_PINNED_TAB: |
| 717 launch_type = LAUNCH_TYPE_PINNED; | 717 launch_type = LAUNCH_TYPE_PINNED; |
| 718 break; | 718 break; |
| 719 case management::LAUNCH_TYPE_OPEN_AS_REGULAR_TAB: | 719 case management::LAUNCH_TYPE_OPEN_AS_REGULAR_TAB: |
| 720 launch_type = LAUNCH_TYPE_REGULAR; | 720 launch_type = LAUNCH_TYPE_REGULAR; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 ManagementAPI::GetFactoryInstance() { | 865 ManagementAPI::GetFactoryInstance() { |
| 866 return g_factory.Pointer(); | 866 return g_factory.Pointer(); |
| 867 } | 867 } |
| 868 | 868 |
| 869 void ManagementAPI::OnListenerAdded(const EventListenerInfo& details) { | 869 void ManagementAPI::OnListenerAdded(const EventListenerInfo& details) { |
| 870 management_event_router_.reset(new ManagementEventRouter(browser_context_)); | 870 management_event_router_.reset(new ManagementEventRouter(browser_context_)); |
| 871 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 871 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
| 872 } | 872 } |
| 873 | 873 |
| 874 } // namespace extensions | 874 } // namespace extensions |
| OLD | NEW |