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

Side by Side Diff: components/password_manager/core/browser/password_store_default.h

Issue 838453003: Open the LoginDatabase on the DB thread, not the UI thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nits from vabr@. Created 5 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_DEFAULT_H_ 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_DEFAULT_H_
6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_DEFAULT_H_ 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_DEFAULT_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "components/password_manager/core/browser/login_database.h" 11 #include "components/password_manager/core/browser/login_database.h"
12 #include "components/password_manager/core/browser/password_store.h" 12 #include "components/password_manager/core/browser/password_store.h"
13 13
14 namespace password_manager { 14 namespace password_manager {
15 15
16 // Simple password store implementation that delegates everything to 16 // Simple password store implementation that delegates everything to
17 // the LoginDatabase. 17 // the LoginDatabase.
18 class PasswordStoreDefault : public PasswordStore { 18 class PasswordStoreDefault : public PasswordStore {
19 public: 19 public:
20 // Takes ownership of |login_db|. 20 // The |login_db| must not have been Init()-ed yet. It will be initialized in
21 // a deferred manner on the DB thread.
21 PasswordStoreDefault( 22 PasswordStoreDefault(
22 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, 23 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner,
23 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, 24 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner,
24 LoginDatabase* login_db); 25 scoped_ptr<LoginDatabase> login_db);
26
27 bool Init(const syncer::SyncableService::StartSyncFlare& flare) override;
28
29 // To be used only for testing.
30 LoginDatabase* login_db() const { return login_db_.get(); }
25 31
26 protected: 32 protected:
27 ~PasswordStoreDefault() override; 33 ~PasswordStoreDefault() override;
28 34
35 // Opens |login_db_| on the DB thread.
36 void InitOnDBThread();
37
29 // Implements PasswordStore interface. 38 // Implements PasswordStore interface.
30 void ReportMetricsImpl(const std::string& sync_username, 39 void ReportMetricsImpl(const std::string& sync_username,
31 bool custom_passphrase_sync_enabled) override; 40 bool custom_passphrase_sync_enabled) override;
32 PasswordStoreChangeList AddLoginImpl( 41 PasswordStoreChangeList AddLoginImpl(
33 const autofill::PasswordForm& form) override; 42 const autofill::PasswordForm& form) override;
34 PasswordStoreChangeList UpdateLoginImpl( 43 PasswordStoreChangeList UpdateLoginImpl(
35 const autofill::PasswordForm& form) override; 44 const autofill::PasswordForm& form) override;
36 PasswordStoreChangeList RemoveLoginImpl( 45 PasswordStoreChangeList RemoveLoginImpl(
37 const autofill::PasswordForm& form) override; 46 const autofill::PasswordForm& form) override;
38 PasswordStoreChangeList RemoveLoginsCreatedBetweenImpl( 47 PasswordStoreChangeList RemoveLoginsCreatedBetweenImpl(
(...skipping 11 matching lines...) Expand all
50 std::vector<autofill::PasswordForm*>* forms) override; 59 std::vector<autofill::PasswordForm*>* forms) override;
51 bool FillBlacklistLogins( 60 bool FillBlacklistLogins(
52 std::vector<autofill::PasswordForm*>* forms) override; 61 std::vector<autofill::PasswordForm*>* forms) override;
53 62
54 protected: 63 protected:
55 inline bool DeleteAndRecreateDatabaseFile() { 64 inline bool DeleteAndRecreateDatabaseFile() {
56 return login_db_->DeleteAndRecreateDatabaseFile(); 65 return login_db_->DeleteAndRecreateDatabaseFile();
57 } 66 }
58 67
59 private: 68 private:
69 // The login SQL database. The LoginDatabase instance is received via the
70 // in an uninitialized state, so as to allow injecting mocks, then Init() is
71 // called on the DB thread in a deferred manner. If opening the DB fails,
72 // |login_db_| will be reset and stay NULL for the lifetime of |this|.
60 scoped_ptr<LoginDatabase> login_db_; 73 scoped_ptr<LoginDatabase> login_db_;
61 74
62 DISALLOW_COPY_AND_ASSIGN(PasswordStoreDefault); 75 DISALLOW_COPY_AND_ASSIGN(PasswordStoreDefault);
63 }; 76 };
64 77
65 } // namespace password_manager 78 } // namespace password_manager
66 79
67 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_DEFAULT_H_ 80 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_DEFAULT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698