Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: chrome/browser/memory/tab_manager_delegate_chromeos.cc

Issue 2877883002: Consolidate two IsArcWindow functions to reduce code duplication (Closed)
Patch Set: Address a comment from sadrul@ Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/memory/tab_manager_delegate_chromeos.h" 5 #include "chrome/browser/memory/tab_manager_delegate_chromeos.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 19 matching lines...) Expand all
30 #include "chrome/browser/memory/memory_kills_monitor.h" 30 #include "chrome/browser/memory/memory_kills_monitor.h"
31 #include "chrome/browser/memory/tab_stats.h" 31 #include "chrome/browser/memory/tab_stats.h"
32 #include "chrome/browser/ui/browser.h" 32 #include "chrome/browser/ui/browser.h"
33 #include "chrome/browser/ui/browser_list.h" 33 #include "chrome/browser/ui/browser_list.h"
34 #include "chrome/browser/ui/tabs/tab_strip_model.h" 34 #include "chrome/browser/ui/tabs/tab_strip_model.h"
35 #include "chrome/common/chrome_constants.h" 35 #include "chrome/common/chrome_constants.h"
36 #include "chrome/common/chrome_features.h" 36 #include "chrome/common/chrome_features.h"
37 #include "chromeos/dbus/dbus_thread_manager.h" 37 #include "chromeos/dbus/dbus_thread_manager.h"
38 #include "components/arc/arc_bridge_service.h" 38 #include "components/arc/arc_bridge_service.h"
39 #include "components/arc/arc_service_manager.h" 39 #include "components/arc/arc_service_manager.h"
40 #include "components/arc/arc_util.h"
40 #include "components/device_event_log/device_event_log.h" 41 #include "components/device_event_log/device_event_log.h"
41 #include "components/exo/shell_surface.h"
42 #include "content/public/browser/browser_thread.h" 42 #include "content/public/browser/browser_thread.h"
43 #include "content/public/browser/notification_service.h" 43 #include "content/public/browser/notification_service.h"
44 #include "content/public/browser/notification_types.h" 44 #include "content/public/browser/notification_types.h"
45 #include "content/public/browser/render_process_host.h" 45 #include "content/public/browser/render_process_host.h"
46 #include "content/public/browser/render_widget_host.h" 46 #include "content/public/browser/render_widget_host.h"
47 #include "content/public/browser/zygote_host_linux.h" 47 #include "content/public/browser/zygote_host_linux.h"
48 #include "ui/aura/window.h"
49 #include "ui/wm/public/activation_client.h" 48 #include "ui/wm/public/activation_client.h"
50 49
51 using base::ProcessHandle; 50 using base::ProcessHandle;
52 using base::TimeDelta; 51 using base::TimeDelta;
53 using base::TimeTicks; 52 using base::TimeTicks;
54 using content::BrowserThread; 53 using content::BrowserThread;
55 54
56 namespace memory { 55 namespace memory {
57 namespace { 56 namespace {
58 57
59 const char kExoShellSurfaceWindowName[] = "ExoShellSurface";
60 const char kArcProcessNamePrefix[] = "org.chromium.arc.";
61
62 // When switching to a new tab the tab's renderer's OOM score needs to be 58 // When switching to a new tab the tab's renderer's OOM score needs to be
63 // updated to reflect its front-most status and protect it from discard. 59 // updated to reflect its front-most status and protect it from discard.
64 // However, doing this immediately might slow down tab switch time, so wait 60 // However, doing this immediately might slow down tab switch time, so wait
65 // a little while before doing the adjustment. 61 // a little while before doing the adjustment.
66 const int kFocusedProcessScoreAdjustIntervalMs = 500; 62 const int kFocusedProcessScoreAdjustIntervalMs = 500;
67 63
68 aura::client::ActivationClient* GetActivationClient() { 64 aura::client::ActivationClient* GetActivationClient() {
69 if (!ash::Shell::HasInstance()) 65 if (!ash::Shell::HasInstance())
70 return nullptr; 66 return nullptr;
71 return aura::client::GetActivationClient(ash::Shell::GetPrimaryRootWindow()); 67 return aura::client::GetActivationClient(ash::Shell::GetPrimaryRootWindow());
72 } 68 }
73 69
74 // Checks if a window renders ARC apps.
75 bool IsArcWindow(aura::Window* window) {
76 if (!window || window->GetName() != kExoShellSurfaceWindowName)
77 return false;
78 std::string application_id = exo::ShellSurface::GetApplicationId(window);
79 return base::StartsWith(application_id, kArcProcessNamePrefix,
80 base::CompareCase::SENSITIVE);
81 }
82
83 bool IsArcMemoryManagementEnabled() { 70 bool IsArcMemoryManagementEnabled() {
84 return base::FeatureList::IsEnabled(features::kArcMemoryManagement); 71 return base::FeatureList::IsEnabled(features::kArcMemoryManagement);
85 } 72 }
86 73
87 void OnSetOomScoreAdj(bool success, const std::string& output) { 74 void OnSetOomScoreAdj(bool success, const std::string& output) {
88 VLOG(2) << "OnSetOomScoreAdj " << success << " " << output; 75 VLOG(2) << "OnSetOomScoreAdj " << success << " " << output;
89 if (!success) 76 if (!success)
90 LOG(ERROR) << "Set OOM score error: " << output; 77 LOG(ERROR) << "Set OOM score error: " << output;
91 else if (!output.empty()) 78 else if (!output.empty())
92 LOG(WARNING) << "Set OOM score: " << output; 79 LOG(WARNING) << "Set OOM score: " << output;
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 return; 320 return;
334 321
335 base::ProcessHandle pid = contents->GetRenderProcessHost()->GetHandle(); 322 base::ProcessHandle pid = contents->GetRenderProcessHost()->GetHandle();
336 AdjustFocusedTabScore(pid); 323 AdjustFocusedTabScore(pid);
337 } 324 }
338 325
339 void TabManagerDelegate::OnWindowActivated( 326 void TabManagerDelegate::OnWindowActivated(
340 aura::client::ActivationChangeObserver::ActivationReason reason, 327 aura::client::ActivationChangeObserver::ActivationReason reason,
341 aura::Window* gained_active, 328 aura::Window* gained_active,
342 aura::Window* lost_active) { 329 aura::Window* lost_active) {
343 if (IsArcWindow(gained_active)) { 330 if (arc::IsArcAppWindow(gained_active)) {
344 // Currently there is no way to know which app is displayed in the ARC 331 // Currently there is no way to know which app is displayed in the ARC
345 // window, so schedule an early adjustment for all processes to reflect 332 // window, so schedule an early adjustment for all processes to reflect
346 // the change. 333 // the change.
347 // Put a dummy FocusedProcess with nspid = kInvalidArcAppNspid for now to 334 // Put a dummy FocusedProcess with nspid = kInvalidArcAppNspid for now to
348 // indicate the focused process is an arc app. 335 // indicate the focused process is an arc app.
349 // TODO(cylee): Fix it when we have nspid info in ARC windows. 336 // TODO(cylee): Fix it when we have nspid info in ARC windows.
350 focused_process_->SetArcAppNspid(FocusedProcess::kInvalidArcAppNspid); 337 focused_process_->SetArcAppNspid(FocusedProcess::kInvalidArcAppNspid);
351 // If the timer is already running (possibly for a tab), it'll be reset 338 // If the timer is already running (possibly for a tab), it'll be reset
352 // here. 339 // here.
353 focus_process_score_adjust_timer_.Start( 340 focus_process_score_adjust_timer_.Start(
354 FROM_HERE, 341 FROM_HERE,
355 TimeDelta::FromMilliseconds(kFocusedProcessScoreAdjustIntervalMs), 342 TimeDelta::FromMilliseconds(kFocusedProcessScoreAdjustIntervalMs),
356 this, &TabManagerDelegate::ScheduleEarlyOomPrioritiesAdjustment); 343 this, &TabManagerDelegate::ScheduleEarlyOomPrioritiesAdjustment);
357 } 344 }
358 if (IsArcWindow(lost_active)) { 345 if (arc::IsArcAppWindow(lost_active)) {
359 // Do not bother adjusting OOM score if the ARC window is deactivated 346 // Do not bother adjusting OOM score if the ARC window is deactivated
360 // shortly. 347 // shortly.
361 if (focused_process_->ResetIfIsArcApp() && 348 if (focused_process_->ResetIfIsArcApp() &&
362 focus_process_score_adjust_timer_.IsRunning()) 349 focus_process_score_adjust_timer_.IsRunning())
363 focus_process_score_adjust_timer_.Stop(); 350 focus_process_score_adjust_timer_.Stop();
364 } 351 }
365 } 352 }
366 353
367 void TabManagerDelegate::ScheduleEarlyOomPrioritiesAdjustment() { 354 void TabManagerDelegate::ScheduleEarlyOomPrioritiesAdjustment() {
368 DCHECK_CURRENTLY_ON(BrowserThread::UI); 355 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 priority += priority_increment; 759 priority += priority_increment;
773 } 760 }
774 761
775 if (oom_scores_to_change.size()) { 762 if (oom_scores_to_change.size()) {
776 GetDebugDaemonClient()->SetOomScoreAdj( 763 GetDebugDaemonClient()->SetOomScoreAdj(
777 oom_scores_to_change, base::Bind(&OnSetOomScoreAdj)); 764 oom_scores_to_change, base::Bind(&OnSetOomScoreAdj));
778 } 765 }
779 } 766 }
780 767
781 } // namespace memory 768 } // namespace memory
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698