| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/browser/devtools/protocol/memory_handler.h" | 5 #include "content/browser/devtools/protocol/memory_handler.h" |
| 6 | 6 |
| 7 #include "base/memory/memory_pressure_listener.h" | 7 #include "base/memory/memory_pressure_listener.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "content/browser/memory/memory_pressure_controller_impl.h" | 9 #include "content/browser/memory/memory_pressure_controller_impl.h" |
| 10 #include "content/public/common/content_features.h" | 10 #include "content/public/common/content_features.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 namespace devtools { | 13 namespace protocol { |
| 14 namespace memory { | |
| 15 | 14 |
| 16 MemoryHandler::MemoryHandler() {} | 15 MemoryHandler::MemoryHandler() {} |
| 17 | 16 |
| 18 MemoryHandler::~MemoryHandler() {} | 17 MemoryHandler::~MemoryHandler() {} |
| 19 | 18 |
| 20 MemoryHandler::Response MemoryHandler::SetPressureNotificationsSuppressed( | 19 void MemoryHandler::Wire(UberDispatcher* dispatcher) { |
| 20 Memory::Dispatcher::wire(dispatcher, this); |
| 21 } |
| 22 |
| 23 Response MemoryHandler::Disable() { |
| 24 return Response::OK(); |
| 25 } |
| 26 |
| 27 Response MemoryHandler::SetPressureNotificationsSuppressed( |
| 21 bool suppressed) { | 28 bool suppressed) { |
| 22 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { | 29 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { |
| 23 return Response::InvalidParams( | 30 return Response::Error( |
| 24 "Cannot enable/disable notifications when memory coordinator is " | 31 "Cannot enable/disable notifications when memory coordinator is " |
| 25 "enabled"); | 32 "enabled"); |
| 26 } | 33 } |
| 27 content::MemoryPressureControllerImpl::GetInstance() | 34 content::MemoryPressureControllerImpl::GetInstance() |
| 28 ->SetPressureNotificationsSuppressedInAllProcesses(suppressed); | 35 ->SetPressureNotificationsSuppressedInAllProcesses(suppressed); |
| 29 return Response::OK(); | 36 return Response::OK(); |
| 30 } | 37 } |
| 31 | 38 |
| 32 MemoryHandler::Response MemoryHandler::SimulatePressureNotification( | 39 Response MemoryHandler::SimulatePressureNotification( |
| 33 const std::string& level) { | 40 const std::string& level) { |
| 34 base::MemoryPressureListener::MemoryPressureLevel parsed_level; | 41 base::MemoryPressureListener::MemoryPressureLevel parsed_level; |
| 35 if (level == kPressureLevelModerate) { | 42 if (level == protocol::Memory::PressureLevelEnum::Moderate) { |
| 36 parsed_level = base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE; | 43 parsed_level = base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE; |
| 37 } else if (level == kPressureLevelCritical) { | 44 } else if (level == protocol::Memory::PressureLevelEnum::Critical) { |
| 38 parsed_level = base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL; | 45 parsed_level = base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL; |
| 39 } else { | 46 } else { |
| 40 return Response::InternalError(base::StringPrintf( | 47 return Response::InvalidParams(base::StringPrintf( |
| 41 "Invalid memory pressure level '%s'", level.c_str())); | 48 "Invalid memory pressure level '%s'", level.c_str())); |
| 42 } | 49 } |
| 43 | 50 |
| 44 MemoryPressureControllerImpl::GetInstance() | 51 MemoryPressureControllerImpl::GetInstance() |
| 45 ->SimulatePressureNotificationInAllProcesses(parsed_level); | 52 ->SimulatePressureNotificationInAllProcesses(parsed_level); |
| 46 return Response::OK(); | 53 return Response::OK(); |
| 47 } | 54 } |
| 48 | 55 |
| 49 MemoryHandler::Response MemoryHandler::GetDOMCounters( | 56 } // namespace protocol |
| 50 int* documents, | |
| 51 int* nodes, | |
| 52 int* event_listeners) { | |
| 53 return Response::FallThrough(); | |
| 54 } | |
| 55 | |
| 56 } // namespace memory | |
| 57 } // namespace devtools | |
| 58 } // namespace content | 57 } // namespace content |
| OLD | NEW |