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

Side by Side Diff: components/profile_service/leveldb_thread.h

Issue 1737933002: mojo leveldb: Get profile and leveldb connected to DOMStorageContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add OWNERS file by request. Created 4 years, 9 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_PROFILE_SERVICE_LEVELDB_THREAD_H_
6 #define COMPONENTS_PROFILE_SERVICE_LEVELDB_THREAD_H_
7
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/thread.h"
12 #include "components/leveldb/public/interfaces/leveldb.mojom.h"
13 #include "mojo/public/cpp/bindings/binding_set.h"
14 #include "mojo/shell/public/cpp/message_loop_ref.h"
15
16 namespace profile {
17
18 // A separate thread for leveldb.
19 //
20 // In the profile application, we need to put leveldb service on its own thread
21 // because otherwise it can deadlock with the profile service. (The leveldb
22 // service asks the profile service for a directory and blocks, but if we
23 // didn't put leveldb on its own thread, it would block its own thread.)
24 class LevelDBThread : public base::Thread,
25 public base::RefCountedThreadSafe<LevelDBThread> {
26 public:
27 LevelDBThread(scoped_ptr<mojo::MessageLoopRef> message_loop_ref,
28 mojo::InterfaceRequest<leveldb::LevelDBService> request);
29
30 // Passes |request| from the caller thread to our LevelDBThread and
31 // binds |request| to the leveldb service thread.
32 void BindNewRequest(mojo::InterfaceRequest<leveldb::LevelDBService> request);
33
34 private:
35 friend class base::RefCountedThreadSafe<LevelDBThread>;
36 ~LevelDBThread() override;
37
38 // Check on each connection error whether we have no more connections.
39 void OnServiceError();
40
41 // Implementation of BindNewRequest run on the LevelDBThread.
42 void BindNewRequestImpl(
43 mojo::InterfaceRequest<leveldb::LevelDBService> request);
44
45 // Overridden from base::SimpleThread:
46 void Init() override;
47 void CleanUp() override;
48
49 // A reference to the parent thread's message loop, which needs to stay alive
50 // while this thread is running. Set on the parent thread; destroyed on the
51 // child thread.
52 scoped_ptr<mojo::MessageLoopRef> parent_thread_message_loop_ref_;
Ben Goodger (Google) 2016/03/11 23:21:38 profile_service_message_loop_ref_? // Hold a refe
53
54 // When we create our underlying LevelDBService, we want to give it a
55 // reference to this object's thread's message loop, so when the service goes
56 // away, this thread gets cleaned up which releases our reference to our
57 // parent thread.
58 mojo::MessageLoopRefFactory thread_message_loop_ref_;
Ben Goodger (Google) 2016/03/11 23:21:38 Shorter: // The lifetime of the leveldb thread's
59
60 // The service shared between all requestors.
61 scoped_ptr<leveldb::LevelDBService> leveldb_service_;
62
63 // All outstanding references to the LevelDBService.
64 scoped_ptr<mojo::BindingSet<leveldb::LevelDBService>> leveldb_bindings_;
65
66 // Used to pass the initial request from the parent thread to the child
67 // thread.
68 mojo::InterfaceRequest<leveldb::LevelDBService> initial_leveldb_request_;
69
70 DISALLOW_COPY_AND_ASSIGN(LevelDBThread);
71 };
72
73 } // namespace profile
74
75 #endif // COMPONENTS_PROFILE_SERVICE_LEVELDB_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698