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

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

Powered by Google App Engine
This is Rietveld 408576698