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

Side by Side Diff: components/webdata/common/web_data_results.h

Issue 2403773002: Remove stl_util's STLDeleteContainerPointers from autofill. (Closed)
Patch Set: rebase Created 4 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_WEBDATA_COMMON_WEB_DATA_RESULTS_H_ 5 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_
6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_ 6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "components/webdata/common/webdata_export.h" 13 #include "components/webdata/common/webdata_export.h"
14 14
15 class WDTypedResult; 15 class WDTypedResult;
16 16
17 // 17 //
18 // Result types for WebDataService. 18 // Result types for WebDataService.
19 // 19 //
20 // clang-format off
20 typedef enum { 21 typedef enum {
21 BOOL_RESULT = 1, // WDResult<bool> 22 BOOL_RESULT = 1, // WDResult<bool>
22 KEYWORDS_RESULT, // WDResult<WDKeywordsResult> 23 KEYWORDS_RESULT, // WDResult<WDKeywordsResult>
23 INT64_RESULT, // WDResult<int64_t> 24 INT64_RESULT, // WDResult<int64_t>
24 #if defined(OS_WIN) 25 #if defined(OS_WIN)
25 PASSWORD_IE7_RESULT, // WDResult<IE7PasswordInfo> 26 PASSWORD_IE7_RESULT, // WDResult<IE7PasswordInfo>
26 #endif 27 #endif
27 WEB_APP_IMAGES, // WDResult<WDAppImagesResult> 28 WEB_APP_IMAGES, // WDResult<WDAppImagesResult>
28 TOKEN_RESULT, // WDResult<std::vector<std::string>> 29 TOKEN_RESULT, // WDResult<std::vector<std::string>>
29 AUTOFILL_VALUE_RESULT, // WDResult<std::vector<base::string16>> 30 AUTOFILL_VALUE_RESULT, // WDResult<std::vector<base::string16>>
30 AUTOFILL_CHANGES, // WDResult<std::vector<AutofillChange>> 31 AUTOFILL_CHANGES, // WDResult<std::vector<AutofillChange>>
31 AUTOFILL_PROFILE_RESULT, // WDResult<AutofillProfile> 32 AUTOFILL_PROFILE_RESULT, // WDResult<AutofillProfile>
32 AUTOFILL_PROFILES_RESULT, // WDResult<std::vector<AutofillProfile*>> 33 AUTOFILL_PROFILES_RESULT, // WDResult<std::vector<
34 // std::unique_ptr<AutofillProfile>>>
33 AUTOFILL_CREDITCARD_RESULT, // WDResult<CreditCard> 35 AUTOFILL_CREDITCARD_RESULT, // WDResult<CreditCard>
34 AUTOFILL_CREDITCARDS_RESULT, // WDResult<std::vector<CreditCard*>> 36 AUTOFILL_CREDITCARDS_RESULT, // WDResult<std::vector<
37 // std::unique_ptr<CreditCard>>>
35 } WDResultType; 38 } WDResultType;
36 39 // clang-format on
37
38 typedef base::Callback<void(const WDTypedResult*)> DestroyCallback;
39 40
40 // 41 //
41 // The top level class for a result. 42 // The top level class for a result.
42 // 43 //
43 class WEBDATA_EXPORT WDTypedResult { 44 class WEBDATA_EXPORT WDTypedResult {
44 public: 45 public:
45 virtual ~WDTypedResult() { 46 virtual ~WDTypedResult() {
46 } 47 }
47 48
48 // Return the result type. 49 // Return the result type.
49 WDResultType GetType() const { 50 WDResultType GetType() const {
50 return type_; 51 return type_;
51 } 52 }
52 53
53 virtual void Destroy() {
54 }
55
56 protected: 54 protected:
57 explicit WDTypedResult(WDResultType type) 55 explicit WDTypedResult(WDResultType type)
58 : type_(type) { 56 : type_(type) {
59 } 57 }
60 58
61 private: 59 private:
62 WDResultType type_; 60 WDResultType type_;
63 DISALLOW_COPY_AND_ASSIGN(WDTypedResult); 61 DISALLOW_COPY_AND_ASSIGN(WDTypedResult);
64 }; 62 };
65 63
66 // A result containing one specific pointer or literal value. 64 // A result containing one specific pointer or literal value.
67 template <class T> class WDResult : public WDTypedResult { 65 template <class T> class WDResult : public WDTypedResult {
68 public: 66 public:
69 WDResult(WDResultType type, const T& v) 67 WDResult(WDResultType type, const T& v) : WDTypedResult(type), value_(v) {}
70 : WDTypedResult(type), value_(v) { 68 WDResult(WDResultType type, T&& v)
71 } 69 : WDTypedResult(type), value_(std::move(v)) {}
72 70
73 ~WDResult() override { 71 ~WDResult() override {}
74 }
75 72
76 // Return a single value result. 73 // Return a single value result.
77 T GetValue() const { 74 const T& GetValue() const { return value_; }
78 return value_; 75 T& GetValue() { return value_; }
79 }
80 76
81 private: 77 private:
82 T value_; 78 T value_;
83 79
84 DISALLOW_COPY_AND_ASSIGN(WDResult); 80 DISALLOW_COPY_AND_ASSIGN(WDResult);
85 }; 81 };
86 82
87 template <class T> class WDDestroyableResult : public WDResult<T> {
88 public:
89 WDDestroyableResult(
90 WDResultType type,
91 const T& v,
92 const DestroyCallback& callback)
93 : WDResult<T>(type, v),
94 callback_(callback) {
95 }
96
97 ~WDDestroyableResult() override {
98 }
99
100 void Destroy() override {
101 if (!callback_.is_null()) {
102 callback_.Run(this);
103 }
104 }
105
106 private:
107 DestroyCallback callback_;
108
109 DISALLOW_COPY_AND_ASSIGN(WDDestroyableResult);
110 };
111
112 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_ 83 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698