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

Side by Side Diff: chrome/browser/sessions/base_session_service.h

Issue 8769013: Remove BrowserThread::UnsafeGetBrowserThread, add UnsafeGetMessageLoopForThread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to lkgr (pure merge). 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 #ifndef CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_
6 #define CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ 6 #define CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/location.h"
11 #include "base/file_path.h" 12 #include "base/file_path.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/profiles/profile_keyed_service.h" 15 #include "chrome/browser/profiles/profile_keyed_service.h"
15 #include "chrome/browser/sessions/session_id.h" 16 #include "chrome/browser/sessions/session_id.h"
16 #include "content/browser/cancelable_request.h" 17 #include "content/browser/cancelable_request.h"
17 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
18 19
19 class NavigationEntry; 20 class NavigationEntry;
20 class Profile; 21 class Profile;
21 class SessionBackend; 22 class SessionBackend;
22 class SessionCommand; 23 class SessionCommand;
23 class TabNavigation; 24 class TabNavigation;
24 25
25 namespace base {
26 class Thread;
27 }
28
29 // BaseSessionService is the super class of both tab restore service and 26 // BaseSessionService is the super class of both tab restore service and
30 // session service. It contains commonality needed by both, in particular 27 // session service. It contains commonality needed by both, in particular
31 // it manages a set of SessionCommands that are periodically sent to a 28 // it manages a set of SessionCommands that are periodically sent to a
32 // SessionBackend. 29 // SessionBackend.
33 class BaseSessionService : public CancelableRequestProvider, 30 class BaseSessionService : public CancelableRequestProvider,
34 public ProfileKeyedService { 31 public ProfileKeyedService {
35 public: 32 public:
36 // Identifies the type of session service this is. This is used by the 33 // Identifies the type of session service this is. This is used by the
37 // backend to determine the name of the files. 34 // backend to determine the name of the files.
38 enum SessionType { 35 enum SessionType {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 private: 75 private:
79 DISALLOW_COPY_AND_ASSIGN(InternalGetCommandsRequest); 76 DISALLOW_COPY_AND_ASSIGN(InternalGetCommandsRequest);
80 }; 77 };
81 78
82 protected: 79 protected:
83 virtual ~BaseSessionService(); 80 virtual ~BaseSessionService();
84 81
85 // Returns the backend. 82 // Returns the backend.
86 SessionBackend* backend() const { return backend_; } 83 SessionBackend* backend() const { return backend_; }
87 84
88 // Returns the thread the backend runs on. This returns NULL during testing.
89 base::Thread* backend_thread() const { return backend_thread_; }
90
91 // Returns the set of commands that needed to be scheduled. The commands 85 // Returns the set of commands that needed to be scheduled. The commands
92 // in the vector are owned by BaseSessionService, until they are scheduled 86 // in the vector are owned by BaseSessionService, until they are scheduled
93 // on the backend at which point the backend owns the commands. 87 // on the backend at which point the backend owns the commands.
94 std::vector<SessionCommand*>& pending_commands() { 88 std::vector<SessionCommand*>& pending_commands() {
95 return pending_commands_; 89 return pending_commands_;
96 } 90 }
97 91
98 // Whether the next save resets the file before writing to it. 92 // Whether the next save resets the file before writing to it.
99 void set_pending_reset(bool value) { pending_reset_ = value; } 93 void set_pending_reset(bool value) { pending_reset_ = value; }
100 bool pending_reset() const { return pending_reset_; } 94 bool pending_reset() const { return pending_reset_; }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 Handle ScheduleGetLastSessionCommands( 144 Handle ScheduleGetLastSessionCommands(
151 InternalGetCommandsRequest* request, 145 InternalGetCommandsRequest* request,
152 CancelableRequestConsumerBase* consumer); 146 CancelableRequestConsumerBase* consumer);
153 147
154 // Invokes ReadCurrentSessionCommands with request on the backend thread. 148 // Invokes ReadCurrentSessionCommands with request on the backend thread.
155 // If testing, ReadLastSessionCommands is invoked directly. 149 // If testing, ReadLastSessionCommands is invoked directly.
156 Handle ScheduleGetCurrentSessionCommands( 150 Handle ScheduleGetCurrentSessionCommands(
157 InternalGetCommandsRequest* request, 151 InternalGetCommandsRequest* request,
158 CancelableRequestConsumerBase* consumer); 152 CancelableRequestConsumerBase* consumer);
159 153
154 // In production, this posts the task to the FILE thread. For
155 // tests, it immediately runs the specified task on the current
156 // thread.
157 bool RunTaskOnBackendThread(const tracked_objects::Location& from_here,
158 const base::Closure& task);
159
160 // Max number of navigation entries in each direction we'll persist. 160 // Max number of navigation entries in each direction we'll persist.
161 static const int max_persist_navigation_count; 161 static const int max_persist_navigation_count;
162 162
163 private: 163 private:
164 // The profile. This may be null during testing. 164 // The profile. This may be null during testing.
165 Profile* profile_; 165 Profile* profile_;
166 166
167 // Path to read from. This is only used if profile_ is NULL. 167 // Path to read from. This is only used if profile_ is NULL.
168 const FilePath& path_; 168 const FilePath& path_;
169 169
170 // The backend. 170 // The backend.
171 scoped_refptr<SessionBackend> backend_; 171 scoped_refptr<SessionBackend> backend_;
172 172
173 // Thread backend tasks are run on, is NULL during testing.
174 base::Thread* backend_thread_;
175
176 // Used to invoke Save. 173 // Used to invoke Save.
177 base::WeakPtrFactory<BaseSessionService> weak_factory_; 174 base::WeakPtrFactory<BaseSessionService> weak_factory_;
178 175
179 // Commands we need to send over to the backend. 176 // Commands we need to send over to the backend.
180 std::vector<SessionCommand*> pending_commands_; 177 std::vector<SessionCommand*> pending_commands_;
181 178
182 // Whether the backend file should be recreated the next time we send 179 // Whether the backend file should be recreated the next time we send
183 // over the commands. 180 // over the commands.
184 bool pending_reset_; 181 bool pending_reset_;
185 182
186 // The number of commands sent to the backend before doing a reset. 183 // The number of commands sent to the backend before doing a reset.
187 int commands_since_reset_; 184 int commands_since_reset_;
188 185
189 DISALLOW_COPY_AND_ASSIGN(BaseSessionService); 186 DISALLOW_COPY_AND_ASSIGN(BaseSessionService);
190 }; 187 };
191 188
192 #endif // CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ 189 #endif // CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/printing/printer_manager_dialog_win.cc ('k') | chrome/browser/sessions/base_session_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698