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

Side by Side Diff: apps/app_keep_alive_service.cc

Issue 60193005: Don't add keep-alives for apps after the app keep-alive service has shut down. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « apps/app_keep_alive_service.h ('k') | apps/app_keep_alive_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "apps/app_keep_alive_service.h" 5 #include "apps/app_keep_alive_service.h"
6 6
7 #include "apps/app_lifetime_monitor.h" 7 #include "apps/app_lifetime_monitor.h"
8 #include "apps/app_lifetime_monitor_factory.h" 8 #include "apps/app_lifetime_monitor_factory.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/lifetime/application_lifetime.h" 10 #include "chrome/browser/lifetime/application_lifetime.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 12
13 namespace apps { 13 namespace apps {
14 14
15 AppKeepAliveService::AppKeepAliveService(content::BrowserContext* context) 15 AppKeepAliveService::AppKeepAliveService(content::BrowserContext* context)
16 : context_(context) { 16 : context_(context), shut_down_(false) {
17 AppLifetimeMonitor* app_lifetime_monitor = 17 AppLifetimeMonitor* app_lifetime_monitor =
18 AppLifetimeMonitorFactory::GetForProfile(static_cast<Profile*>(context)); 18 AppLifetimeMonitorFactory::GetForProfile(static_cast<Profile*>(context));
19 app_lifetime_monitor->AddObserver(this); 19 app_lifetime_monitor->AddObserver(this);
20 } 20 }
21 21
22 AppKeepAliveService::~AppKeepAliveService() {} 22 AppKeepAliveService::~AppKeepAliveService() {}
23 23
24 void AppKeepAliveService::Shutdown() { 24 void AppKeepAliveService::Shutdown() {
25 AppLifetimeMonitor* app_lifetime_monitor = 25 AppLifetimeMonitor* app_lifetime_monitor =
26 AppLifetimeMonitorFactory::GetForProfile(static_cast<Profile*>(context_)); 26 AppLifetimeMonitorFactory::GetForProfile(static_cast<Profile*>(context_));
27 app_lifetime_monitor->RemoveObserver(this); 27 app_lifetime_monitor->RemoveObserver(this);
28 OnChromeTerminating(); 28 OnChromeTerminating();
29 } 29 }
30 30
31 void AppKeepAliveService::OnAppStart(Profile* profile, 31 void AppKeepAliveService::OnAppStart(Profile* profile,
32 const std::string& app_id) { 32 const std::string& app_id) {
33 if (profile != context_) 33 if (profile != context_ || shut_down_)
34 return; 34 return;
35 35
36 if (running_apps_.insert(app_id).second) 36 if (running_apps_.insert(app_id).second)
37 chrome::StartKeepAlive(); 37 chrome::StartKeepAlive();
38 } 38 }
39 39
40 void AppKeepAliveService::OnAppStop(Profile* profile, 40 void AppKeepAliveService::OnAppStop(Profile* profile,
41 const std::string& app_id) { 41 const std::string& app_id) {
42 if (profile != context_) 42 if (profile != context_)
43 return; 43 return;
44 44
45 if (running_apps_.erase(app_id)) 45 if (running_apps_.erase(app_id))
46 chrome::EndKeepAlive(); 46 chrome::EndKeepAlive();
47 } 47 }
48 48
49 void AppKeepAliveService::OnAppActivated(Profile* profile, 49 void AppKeepAliveService::OnAppActivated(Profile* profile,
50 const std::string& app_id) {} 50 const std::string& app_id) {}
51 51
52 void AppKeepAliveService::OnAppDeactivated(Profile* profile, 52 void AppKeepAliveService::OnAppDeactivated(Profile* profile,
53 const std::string& app_id) {} 53 const std::string& app_id) {}
54 54
55 void AppKeepAliveService::OnChromeTerminating() { 55 void AppKeepAliveService::OnChromeTerminating() {
56 shut_down_ = true;
56 size_t keep_alives = running_apps_.size(); 57 size_t keep_alives = running_apps_.size();
57 running_apps_.clear(); 58 running_apps_.clear();
58 59
59 // In some tests, the message loop isn't running during shutdown and ending 60 // In some tests, the message loop isn't running during shutdown and ending
60 // the last keep alive in that case CHECKs. 61 // the last keep alive in that case CHECKs.
61 if (!base::MessageLoop::current() || 62 if (!base::MessageLoop::current() ||
62 base::MessageLoop::current()->is_running()) { 63 base::MessageLoop::current()->is_running()) {
63 while (keep_alives--) 64 while (keep_alives--)
64 chrome::EndKeepAlive(); 65 chrome::EndKeepAlive();
65 } 66 }
66 } 67 }
67 68
68 } // namespace apps 69 } // namespace apps
OLDNEW
« no previous file with comments | « apps/app_keep_alive_service.h ('k') | apps/app_keep_alive_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698