Home | History | Annotate | Download | only in webdata
      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 #include "chrome/browser/webdata/web_data_service.h"
      6 
      7 #include "base/task.h"
      8 #include "chrome/browser/password_manager/ie7_password.h"
      9 #include "chrome/browser/webdata/web_database.h"
     10 
     11 void WebDataService::AddIE7Login(const IE7PasswordInfo& info) {
     12   GenericRequest<IE7PasswordInfo>* request =
     13       new GenericRequest<IE7PasswordInfo>(this, GetNextRequestHandle(), NULL,
     14                                           info);
     15   RegisterRequest(request);
     16   ScheduleTask(NewRunnableMethod(this, &WebDataService::AddIE7LoginImpl,
     17                                  request));
     18 }
     19 
     20 void WebDataService::RemoveIE7Login(const IE7PasswordInfo& info) {
     21   GenericRequest<IE7PasswordInfo>* request =
     22       new GenericRequest<IE7PasswordInfo>(this, GetNextRequestHandle(), NULL,
     23                                           info);
     24   RegisterRequest(request);
     25   ScheduleTask(NewRunnableMethod(this, &WebDataService::RemoveIE7LoginImpl,
     26                                  request));
     27 }
     28 
     29 WebDataService::Handle WebDataService::GetIE7Login(
     30     const IE7PasswordInfo& info,
     31     WebDataServiceConsumer* consumer) {
     32   GenericRequest<IE7PasswordInfo>* request =
     33       new GenericRequest<IE7PasswordInfo>(this, GetNextRequestHandle(),
     34                                           consumer, info);
     35   RegisterRequest(request);
     36   ScheduleTask(NewRunnableMethod(this, &WebDataService::GetIE7LoginImpl,
     37                                  request));
     38   return request->GetHandle();
     39 }
     40 
     41 void WebDataService::AddIE7LoginImpl(GenericRequest<IE7PasswordInfo>* request) {
     42   if (db_ && !request->IsCancelled()) {
     43     if (db_->GetLoginsTable()->AddIE7Login(request->GetArgument()))
     44       ScheduleCommit();
     45   }
     46   request->RequestComplete();
     47 }
     48 
     49 void WebDataService::RemoveIE7LoginImpl(
     50     GenericRequest<IE7PasswordInfo>* request) {
     51   if (db_ && !request->IsCancelled()) {
     52     if (db_->GetLoginsTable()->RemoveIE7Login(request->GetArgument()))
     53       ScheduleCommit();
     54   }
     55   request->RequestComplete();
     56 }
     57 
     58 void WebDataService::GetIE7LoginImpl(
     59     GenericRequest<IE7PasswordInfo>* request) {
     60   if (db_ && !request->IsCancelled()) {
     61     IE7PasswordInfo result;
     62     db_->GetLoginsTable()->GetIE7Login(request->GetArgument(), &result);
     63     request->SetResult(
     64         new WDResult<IE7PasswordInfo>(PASSWORD_IE7_RESULT, result));
     65   }
     66   request->RequestComplete();
     67 }
     68