Home | History | Annotate | Download | only in password_manager
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_DEFAULT_H_
      6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_DEFAULT_H_
      7 #pragma once
      8 
      9 #include <vector>
     10 
     11 #include "base/memory/ref_counted.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #include "chrome/browser/password_manager/login_database.h"
     14 #include "chrome/browser/password_manager/password_store.h"
     15 
     16 class Profile;
     17 class WebDataService;
     18 
     19 // Simple password store implementation that delegates everything to
     20 // the LoginDatabase.
     21 class PasswordStoreDefault : public PasswordStore {
     22  public:
     23   // Takes ownership of |login_db|.
     24   PasswordStoreDefault(LoginDatabase* login_db,
     25                        Profile* profile,
     26                        WebDataService* web_data_service);
     27 
     28  protected:
     29   virtual ~PasswordStoreDefault();
     30 
     31   // Implements PasswordStore interface.
     32   virtual void Shutdown();
     33   virtual void ReportMetricsImpl();
     34   virtual void AddLoginImpl(const webkit_glue::PasswordForm& form);
     35   virtual void UpdateLoginImpl(const webkit_glue::PasswordForm& form);
     36   virtual void RemoveLoginImpl(const webkit_glue::PasswordForm& form);
     37   virtual void RemoveLoginsCreatedBetweenImpl(const base::Time& delete_begin,
     38                                               const base::Time& delete_end);
     39   virtual void GetLoginsImpl(GetLoginsRequest* request,
     40                              const webkit_glue::PasswordForm& form);
     41   virtual void GetAutofillableLoginsImpl(GetLoginsRequest* request);
     42   virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request);
     43   virtual bool FillAutofillableLogins(
     44       std::vector<webkit_glue::PasswordForm*>* forms);
     45   virtual bool FillBlacklistLogins(
     46       std::vector<webkit_glue::PasswordForm*>* forms);
     47 
     48   scoped_refptr<WebDataService> web_data_service_;
     49 
     50  protected:
     51   inline bool DeleteAndRecreateDatabaseFile() {
     52     return login_db_->DeleteAndRecreateDatabaseFile();
     53   }
     54 
     55  private:
     56   class MigrateHelper;
     57 
     58   // Migrates logins from the WDS to the LoginDatabase.
     59   void MigrateIfNecessary();
     60 
     61   scoped_ptr<LoginDatabase> login_db_;
     62   Profile* profile_;
     63 
     64   scoped_ptr<MigrateHelper> migrate_helper_;
     65 
     66   DISALLOW_COPY_AND_ASSIGN(PasswordStoreDefault);
     67 };
     68 
     69 #endif  // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_DEFAULT_H_
     70