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

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

Issue 8677030: base::Bind: Convert more of chrome/browser/sessions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Build fix. Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/session_service.h" 5 #include "chrome/browser/sessions/session_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h"
13 #include "base/bind_helpers.h"
12 #include "base/file_util.h" 14 #include "base/file_util.h"
13 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
14 #include "base/message_loop.h" 16 #include "base/message_loop.h"
15 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
16 #include "base/pickle.h" 18 #include "base/pickle.h"
17 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
18 #include "chrome/browser/extensions/extension_tab_helper.h" 20 #include "chrome/browser/extensions/extension_tab_helper.h"
19 #include "chrome/browser/prefs/session_startup_pref.h" 21 #include "chrome/browser/prefs/session_startup_pref.h"
20 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/sessions/restore_tab_helper.h" 23 #include "chrome/browser/sessions/restore_tab_helper.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 namespace { 71 namespace {
70 72
71 // The callback from GetLastSession is internally routed to SessionService 73 // The callback from GetLastSession is internally routed to SessionService
72 // first and then the caller. This is done so that the SessionWindows can be 74 // first and then the caller. This is done so that the SessionWindows can be
73 // recreated from the SessionCommands and the SessionWindows passed to the 75 // recreated from the SessionCommands and the SessionWindows passed to the
74 // caller. The following class is used for this. 76 // caller. The following class is used for this.
75 class InternalSessionRequest 77 class InternalSessionRequest
76 : public BaseSessionService::InternalGetCommandsRequest { 78 : public BaseSessionService::InternalGetCommandsRequest {
77 public: 79 public:
78 InternalSessionRequest( 80 InternalSessionRequest(
79 CallbackType* callback, 81 const CallbackType& callback,
80 SessionService::SessionCallback* real_callback) 82 SessionService::SessionCallback* real_callback)
81 : BaseSessionService::InternalGetCommandsRequest(callback), 83 : BaseSessionService::InternalGetCommandsRequest(callback),
82 real_callback(real_callback) { 84 real_callback(real_callback) {
83 } 85 }
84 86
85 // The callback supplied to GetLastSession and GetCurrentSession. 87 // The callback supplied to GetLastSession and GetCurrentSession.
86 scoped_ptr<SessionService::SessionCallback> real_callback; 88 scoped_ptr<SessionService::SessionCallback> real_callback;
87 89
88 private: 90 private:
89 ~InternalSessionRequest() {} 91 ~InternalSessionRequest() {}
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 void SessionService::MoveCurrentSessionToLastSession() { 178 void SessionService::MoveCurrentSessionToLastSession() {
177 pending_tab_close_ids_.clear(); 179 pending_tab_close_ids_.clear();
178 window_closing_ids_.clear(); 180 window_closing_ids_.clear();
179 pending_window_close_ids_.clear(); 181 pending_window_close_ids_.clear();
180 182
181 Save(); 183 Save();
182 184
183 if (!backend_thread()) { 185 if (!backend_thread()) {
184 backend()->MoveCurrentSessionToLastSession(); 186 backend()->MoveCurrentSessionToLastSession();
185 } else { 187 } else {
186 backend_thread()->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 188 backend_thread()->message_loop()->PostTask(
187 backend(), &SessionBackend::MoveCurrentSessionToLastSession)); 189 FROM_HERE, base::Bind(&SessionBackend::MoveCurrentSessionToLastSession,
190 backend()));
188 } 191 }
189 } 192 }
190 193
191 void SessionService::SetTabWindow(const SessionID& window_id, 194 void SessionService::SetTabWindow(const SessionID& window_id,
192 const SessionID& tab_id) { 195 const SessionID& tab_id) {
193 if (!ShouldTrackChangesToWindow(window_id)) 196 if (!ShouldTrackChangesToWindow(window_id))
194 return; 197 return;
195 198
196 ScheduleCommand(CreateSetTabWindowCommand(window_id, tab_id)); 199 ScheduleCommand(CreateSetTabWindowCommand(window_id, tab_id));
197 } 200 }
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 return; 415 return;
413 416
414 ScheduleCommand(CreateSetSelectedTabInWindow(window_id, index)); 417 ScheduleCommand(CreateSetSelectedTabInWindow(window_id, index));
415 } 418 }
416 419
417 SessionService::Handle SessionService::GetLastSession( 420 SessionService::Handle SessionService::GetLastSession(
418 CancelableRequestConsumerBase* consumer, 421 CancelableRequestConsumerBase* consumer,
419 SessionCallback* callback) { 422 SessionCallback* callback) {
420 return ScheduleGetLastSessionCommands( 423 return ScheduleGetLastSessionCommands(
421 new InternalSessionRequest( 424 new InternalSessionRequest(
422 NewCallback(this, &SessionService::OnGotSessionCommands), 425 base::Bind(&SessionService::OnGotSessionCommands,
423 callback), consumer); 426 base::Unretained(this)),
427 callback),
428 consumer);
424 } 429 }
425 430
426 SessionService::Handle SessionService::GetCurrentSession( 431 SessionService::Handle SessionService::GetCurrentSession(
427 CancelableRequestConsumerBase* consumer, 432 CancelableRequestConsumerBase* consumer,
428 SessionCallback* callback) { 433 SessionCallback* callback) {
429 if (pending_window_close_ids_.empty()) { 434 if (pending_window_close_ids_.empty()) {
430 // If there are no pending window closes, we can get the current session 435 // If there are no pending window closes, we can get the current session
431 // from memory. 436 // from memory.
432 scoped_refptr<InternalSessionRequest> request(new InternalSessionRequest( 437 scoped_refptr<InternalSessionRequest> request(new InternalSessionRequest(
433 NewCallback(this, &SessionService::OnGotSessionCommands), 438 base::Bind(&SessionService::OnGotSessionCommands,
439 base::Unretained(this)),
434 callback)); 440 callback));
435 AddRequest(request, consumer); 441 AddRequest(request, consumer);
436 IdToRange tab_to_available_range; 442 IdToRange tab_to_available_range;
437 std::set<SessionID::id_type> windows_to_track; 443 std::set<SessionID::id_type> windows_to_track;
438 BuildCommandsFromBrowsers(&(request->commands), 444 BuildCommandsFromBrowsers(&(request->commands),
439 &tab_to_available_range, 445 &tab_to_available_range,
440 &windows_to_track); 446 &windows_to_track);
441 request->ForwardResult( 447 request->ForwardResult(request->handle(), request);
442 BaseSessionService::InternalGetCommandsRequest::TupleType(
443 request->handle(), request));
444 return request->handle(); 448 return request->handle();
445 } else { 449 } else {
446 // If there are pending window closes, read the current session from disk. 450 // If there are pending window closes, read the current session from disk.
447 return ScheduleGetCurrentSessionCommands( 451 return ScheduleGetCurrentSessionCommands(
448 new InternalSessionRequest( 452 new InternalSessionRequest(
449 NewCallback(this, &SessionService::OnGotSessionCommands), 453 base::Bind(&SessionService::OnGotSessionCommands,
450 callback), consumer); 454 base::Unretained(this)),
455 callback),
456 consumer);
451 } 457 }
452 } 458 }
453 459
454 void SessionService::Save() { 460 void SessionService::Save() {
455 bool had_commands = !pending_commands().empty(); 461 bool had_commands = !pending_commands().empty();
456 BaseSessionService::Save(); 462 BaseSessionService::Save();
457 if (had_commands) { 463 if (had_commands) {
458 RecordSessionUpdateHistogramData( 464 RecordSessionUpdateHistogramData(
459 chrome::NOTIFICATION_SESSION_SERVICE_SAVED, 465 chrome::NOTIFICATION_SESSION_SERVICE_SAVED,
460 &last_updated_save_time_); 466 &last_updated_save_time_);
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after
1533 50); 1539 50);
1534 if (use_long_period) { 1540 if (use_long_period) {
1535 std::string long_name_("SessionRestore.SaveLongPeriod"); 1541 std::string long_name_("SessionRestore.SaveLongPeriod");
1536 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, 1542 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_,
1537 delta, 1543 delta,
1538 save_delay_in_mins_, 1544 save_delay_in_mins_,
1539 save_delay_in_hrs_, 1545 save_delay_in_hrs_,
1540 50); 1546 50);
1541 } 1547 }
1542 } 1548 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_service.h ('k') | chrome/browser/sessions/tab_restore_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698