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

Side by Side Diff: chrome/browser/sessions/chrome_tab_restore_service_client.cc

Issue 1309363007: [sessions] Remove most knowledge of //chrome from core tab restore code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tab_restore_service_client
Patch Set: Make OnTabRestored() optional Created 5 years, 3 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/sessions/chrome_tab_restore_service_client.h" 5 #include "chrome/browser/sessions/chrome_tab_restore_service_client.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/sessions/session_service.h" 8 #include "chrome/browser/sessions/session_service.h"
9 #include "chrome/browser/sessions/session_service_factory.h" 9 #include "chrome/browser/sessions/session_service_factory.h"
10 #include "chrome/common/url_constants.h"
11
12 #if defined(ENABLE_EXTENSIONS)
13 #include "chrome/common/extensions/extension_constants.h"
14 #include "chrome/common/extensions/extension_metrics.h"
15 #include "extensions/browser/extension_registry.h"
16 #include "extensions/common/extension.h"
17 #include "extensions/common/extension_set.h"
18 #endif
19
20 namespace {
21
22 void RecordAppLaunch(Profile* profile, const GURL& url) {
23 #if defined(ENABLE_EXTENSIONS)
24 const extensions::Extension* extension =
25 extensions::ExtensionRegistry::Get(profile)
26 ->enabled_extensions()
27 .GetAppByURL(url);
28 if (!extension)
29 return;
30
31 extensions::RecordAppLaunchType(
32 extension_misc::APP_LAUNCH_NTP_RECENTLY_CLOSED, extension->GetType());
33 #endif // defined(ENABLE_EXTENSIONS)
34 }
35
36 } // namespace
10 37
11 ChromeTabRestoreServiceClient::ChromeTabRestoreServiceClient(Profile* profile) 38 ChromeTabRestoreServiceClient::ChromeTabRestoreServiceClient(Profile* profile)
12 : profile_(profile) {} 39 : profile_(profile) {}
13 40
14 ChromeTabRestoreServiceClient::~ChromeTabRestoreServiceClient() {} 41 ChromeTabRestoreServiceClient::~ChromeTabRestoreServiceClient() {}
15 42
43 base::FilePath ChromeTabRestoreServiceClient::GetPathToSaveTo() {
44 return profile_->GetPath();
45 }
46
47 GURL ChromeTabRestoreServiceClient::GetNewTabURL() {
48 return GURL(chrome::kChromeUINewTabURL);
49 }
50
16 bool ChromeTabRestoreServiceClient::HasLastSession() { 51 bool ChromeTabRestoreServiceClient::HasLastSession() {
17 #if defined(ENABLE_SESSION_SERVICE) 52 #if defined(ENABLE_SESSION_SERVICE)
18 SessionService* session_service = 53 SessionService* session_service =
19 SessionServiceFactory::GetForProfile(profile_); 54 SessionServiceFactory::GetForProfile(profile_);
20 Profile::ExitType exit_type = profile_->GetLastSessionExitType(); 55 Profile::ExitType exit_type = profile_->GetLastSessionExitType();
21 // The previous session crashed and wasn't restored, or was a forced 56 // The previous session crashed and wasn't restored, or was a forced
22 // shutdown. Both of which won't have notified us of the browser close so 57 // shutdown. Both of which won't have notified us of the browser close so
23 // that we need to load the windows from session service (which will have 58 // that we need to load the windows from session service (which will have
24 // saved them). 59 // saved them).
25 return (!profile_->restored_last_session() && session_service && 60 return (!profile_->restored_last_session() && session_service &&
26 (exit_type == Profile::EXIT_CRASHED || 61 (exit_type == Profile::EXIT_CRASHED ||
27 exit_type == Profile::EXIT_SESSION_ENDED)); 62 exit_type == Profile::EXIT_SESSION_ENDED));
28 #else 63 #else
29 return false; 64 return false;
30 #endif 65 #endif
31 } 66 }
32 67
33 void ChromeTabRestoreServiceClient::GetLastSession( 68 void ChromeTabRestoreServiceClient::GetLastSession(
34 const sessions::GetLastSessionCallback& callback, 69 const sessions::GetLastSessionCallback& callback,
35 base::CancelableTaskTracker* tracker) { 70 base::CancelableTaskTracker* tracker) {
36 DCHECK(HasLastSession()); 71 DCHECK(HasLastSession());
37 #if defined(ENABLE_SESSION_SERVICE) 72 #if defined(ENABLE_SESSION_SERVICE)
38 SessionServiceFactory::GetForProfile(profile_) 73 SessionServiceFactory::GetForProfile(profile_)
39 ->GetLastSession(callback, tracker); 74 ->GetLastSession(callback, tracker);
40 #endif 75 #endif
41 } 76 }
77
78 void ChromeTabRestoreServiceClient::OnTabRestored(const GURL& url) {
79 RecordAppLaunch(profile_, url);
80 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/chrome_tab_restore_service_client.h ('k') | chrome/browser/sessions/in_memory_tab_restore_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698