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

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

Issue 2133503002: arc: Revamp the ArcBridgeService interface (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: More rebasing Created 4 years, 5 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 <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 int TabManagerDelegate::MemoryStat::EstimatedMemoryFreedKB( 277 int TabManagerDelegate::MemoryStat::EstimatedMemoryFreedKB(
278 base::ProcessHandle pid) { 278 base::ProcessHandle pid) {
279 std::unique_ptr<base::ProcessMetrics> process_metrics( 279 std::unique_ptr<base::ProcessMetrics> process_metrics(
280 base::ProcessMetrics::CreateProcessMetrics(pid)); 280 base::ProcessMetrics::CreateProcessMetrics(pid));
281 base::WorkingSetKBytes mem_usage; 281 base::WorkingSetKBytes mem_usage;
282 process_metrics->GetWorkingSetKBytes(&mem_usage); 282 process_metrics->GetWorkingSetKBytes(&mem_usage);
283 return mem_usage.priv; 283 return mem_usage.priv;
284 } 284 }
285 285
286 class TabManagerDelegate::UmaReporter { 286 class TabManagerDelegate::UmaReporter {
287 public: 287 public:
288 UmaReporter() 288 UmaReporter() : last_kill_time_(), total_kills_(0) {}
289 : last_kill_time_(), total_kills_(0) {} 289 ~UmaReporter() {}
290 ~UmaReporter() {} 290 void ReportKill(const int memory_freed);
291 void ReportKill(const int memory_freed);
292 291
293 private: 292 private:
294 base::Time last_kill_time_; 293 base::Time last_kill_time_;
295 int total_kills_; 294 int total_kills_;
296 }; 295 };
297 296
298 void TabManagerDelegate::UmaReporter::ReportKill(const int memory_freed) { 297 void TabManagerDelegate::UmaReporter::ReportKill(const int memory_freed) {
299 base::Time now = base::Time::Now(); 298 base::Time now = base::Time::Now();
300 const TimeDelta time_delta = 299 const TimeDelta time_delta =
301 last_kill_time_.is_null() ? 300 last_kill_time_.is_null() ?
302 TimeDelta::FromSeconds(arc::kMaxOomMemoryKillTimeDeltaSecs) : 301 TimeDelta::FromSeconds(arc::kMaxOomMemoryKillTimeDeltaSecs) :
303 (now - last_kill_time_); 302 (now - last_kill_time_);
304 UMA_HISTOGRAM_OOM_KILL_TIME_INTERVAL( 303 UMA_HISTOGRAM_OOM_KILL_TIME_INTERVAL(
305 "Arc.LowMemoryKiller.TimeDelta", time_delta); 304 "Arc.LowMemoryKiller.TimeDelta", time_delta);
(...skipping 23 matching lines...) Expand all
329 uma_(new UmaReporter()), 328 uma_(new UmaReporter()),
330 weak_ptr_factory_(this) { 329 weak_ptr_factory_(this) {
331 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 330 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
332 content::NotificationService::AllBrowserContextsAndSources()); 331 content::NotificationService::AllBrowserContextsAndSources());
333 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 332 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
334 content::NotificationService::AllBrowserContextsAndSources()); 333 content::NotificationService::AllBrowserContextsAndSources());
335 registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, 334 registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
336 content::NotificationService::AllBrowserContextsAndSources()); 335 content::NotificationService::AllBrowserContextsAndSources());
337 auto arc_bridge_service = arc::ArcBridgeService::Get(); 336 auto arc_bridge_service = arc::ArcBridgeService::Get();
338 if (arc_bridge_service) 337 if (arc_bridge_service)
339 arc_bridge_service->AddObserver(this); 338 arc_bridge_service->process()->AddObserver(this);
340 auto activation_client = GetActivationClient(); 339 auto activation_client = GetActivationClient();
341 if (activation_client) 340 if (activation_client)
342 activation_client->AddObserver(this); 341 activation_client->AddObserver(this);
343 BrowserList::GetInstance()->AddObserver(this); 342 BrowserList::GetInstance()->AddObserver(this);
344 } 343 }
345 344
346 TabManagerDelegate::~TabManagerDelegate() { 345 TabManagerDelegate::~TabManagerDelegate() {
347 BrowserList::GetInstance()->RemoveObserver(this); 346 BrowserList::GetInstance()->RemoveObserver(this);
348 auto activation_client = GetActivationClient(); 347 auto activation_client = GetActivationClient();
349 if (activation_client) 348 if (activation_client)
350 activation_client->RemoveObserver(this); 349 activation_client->RemoveObserver(this);
351 auto arc_bridge_service = arc::ArcBridgeService::Get(); 350 auto arc_bridge_service = arc::ArcBridgeService::Get();
352 if (arc_bridge_service) 351 if (arc_bridge_service)
353 arc_bridge_service->RemoveObserver(this); 352 arc_bridge_service->process()->RemoveObserver(this);
354 } 353 }
355 354
356 void TabManagerDelegate::OnBrowserSetLastActive(Browser* browser) { 355 void TabManagerDelegate::OnBrowserSetLastActive(Browser* browser) {
357 // Set OOM score to the selected tab when a browser window is activated. 356 // Set OOM score to the selected tab when a browser window is activated.
358 // content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED didn't catch the 357 // content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED didn't catch the
359 // case (like when switching focus between 2 browser windows) so we need to 358 // case (like when switching focus between 2 browser windows) so we need to
360 // handle it here. 359 // handle it here.
361 TabStripModel* tab_strip_model = browser->tab_strip_model(); 360 TabStripModel* tab_strip_model = browser->tab_strip_model();
362 int selected_index = tab_strip_model->active_index(); 361 int selected_index = tab_strip_model->active_index();
363 content::WebContents* contents = 362 content::WebContents* contents =
364 tab_strip_model->GetWebContentsAt(selected_index); 363 tab_strip_model->GetWebContentsAt(selected_index);
365 if (!contents) 364 if (!contents)
366 return; 365 return;
367 366
368 base::ProcessHandle pid = contents->GetRenderProcessHost()->GetHandle(); 367 base::ProcessHandle pid = contents->GetRenderProcessHost()->GetHandle();
369 AdjustFocusedTabScore(pid); 368 AdjustFocusedTabScore(pid);
370 } 369 }
371 370
372 void TabManagerDelegate::OnProcessInstanceReady() { 371 void TabManagerDelegate::OnInstanceReady() {
373 auto arc_bridge_service = arc::ArcBridgeService::Get(); 372 auto arc_bridge_service = arc::ArcBridgeService::Get();
374 DCHECK(arc_bridge_service); 373 DCHECK(arc_bridge_service);
375 374
376 arc_process_instance_ = arc_bridge_service->process_instance(); 375 arc_process_instance_ = arc_bridge_service->process()->instance();
377 arc_process_instance_version_ = arc_bridge_service->process_version(); 376 arc_process_instance_version_ = arc_bridge_service->process()->version();
378 377
379 DCHECK(arc_process_instance_); 378 DCHECK(arc_process_instance_);
380 379
381 if (!IsArcMemoryManagementEnabled()) 380 if (!IsArcMemoryManagementEnabled())
382 return; 381 return;
383 382
384 if (arc_process_instance_version_ < 2) { 383 if (arc_process_instance_version_ < 2) {
385 VLOG(1) << "ProcessInstance version < 2 does not " 384 VLOG(1) << "ProcessInstance version < 2 does not "
386 "support DisableBuiltinOomAdjustment() yet."; 385 "support DisableBuiltinOomAdjustment() yet.";
387 return; 386 return;
388 } 387 }
389 // Stop Android system-wide oom_adj adjustment since this class will 388 // Stop Android system-wide oom_adj adjustment since this class will
390 // take over oom_score_adj settings. 389 // take over oom_score_adj settings.
391 arc_process_instance_->DisableBuiltinOomAdjustment(); 390 arc_process_instance_->DisableBuiltinOomAdjustment();
392 391
393 if (arc_process_instance_version_ < 3) { 392 if (arc_process_instance_version_ < 3) {
394 VLOG(1) << "arc::ProcessInstance version < 3 does not " 393 VLOG(1) << "arc::ProcessInstance version < 3 does not "
395 "support DisableLowMemoryKiller() yet."; 394 "support DisableLowMemoryKiller() yet.";
396 return; 395 return;
397 } 396 }
398 VLOG(2) << "Disable LowMemoryKiller"; 397 VLOG(2) << "Disable LowMemoryKiller";
399 arc_process_instance_->DisableLowMemoryKiller(); 398 arc_process_instance_->DisableLowMemoryKiller();
400 } 399 }
401 400
402 void TabManagerDelegate::OnProcessInstanceClosed() { 401 void TabManagerDelegate::OnInstanceClosed() {
403 arc_process_instance_ = nullptr; 402 arc_process_instance_ = nullptr;
404 arc_process_instance_version_ = 0; 403 arc_process_instance_version_ = 0;
405 } 404 }
406 405
407 void TabManagerDelegate::OnWindowActivated( 406 void TabManagerDelegate::OnWindowActivated(
408 aura::client::ActivationChangeObserver::ActivationReason reason, 407 aura::client::ActivationChangeObserver::ActivationReason reason,
409 aura::Window* gained_active, 408 aura::Window* gained_active,
410 aura::Window* lost_active) { 409 aura::Window* lost_active) {
411 if (IsArcWindow(gained_active)) { 410 if (IsArcWindow(gained_active)) {
412 // Currently there is no way to know which app is displayed in the ARC 411 // Currently there is no way to know which app is displayed in the ARC
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 } 815 }
817 } 816 }
818 priority += priority_increment; 817 priority += priority_increment;
819 } 818 }
820 819
821 if (oom_score_for_tabs.size()) 820 if (oom_score_for_tabs.size())
822 SetOomScoreAdjForTabs(oom_score_for_tabs); 821 SetOomScoreAdjForTabs(oom_score_for_tabs);
823 } 822 }
824 823
825 } // namespace memory 824 } // namespace memory
OLDNEW
« no previous file with comments | « chrome/browser/memory/tab_manager_delegate_chromeos.h ('k') | chrome/browser/task_management/providers/arc/arc_process_task.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698