1 // Copyright 2019 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_CHROMEOS_LOGIN_SCREENS_RECOMMEND_APPS_FAKE_RECOMMEND_APPS_FETCHER_DELEGATE_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_RECOMMEND_APPS_FAKE_RECOMMEND_APPS_FETCHER_DELEGATE_H_ 7 8 #include "chrome/browser/chromeos/login/screens/recommend_apps/recommend_apps_fetcher_delegate.h" 9 10 #include "base/callback.h" 11 #include "base/values.h" 12 13 namespace chromeos { 14 15 // Delegate interface used by RecommendAppsFetcher to report its results. 16 class FakeRecommendAppsFetcherDelegate : public RecommendAppsFetcherDelegate { 17 public: 18 // Set of possible results reported by RecommendAppsFetcher. 19 enum class Result { UNKNOWN, SUCCESS, LOAD_ERROR, PARSE_ERROR }; 20 21 FakeRecommendAppsFetcherDelegate(); 22 ~FakeRecommendAppsFetcherDelegate() override; 23 24 FakeRecommendAppsFetcherDelegate( 25 const FakeRecommendAppsFetcherDelegate& other) = delete; 26 FakeRecommendAppsFetcherDelegate& operator=( 27 const FakeRecommendAppsFetcherDelegate& other) = delete; 28 loaded_apps()29 const base::Value& loaded_apps() const { return loaded_apps_; } result()30 Result result() const { return result_; } 31 32 // Waits until a result is reported to the delegate, and returns the returned 33 // result type. 34 Result WaitForResult(); 35 36 // Resets the delegate - it clears any previously reported fetcher results. Reset()37 void Reset() { 38 loaded_apps_ = base::Value(); 39 result_ = Result::UNKNOWN; 40 } 41 42 // RecommendAppsFetcherDelegate: 43 void OnLoadSuccess(const base::Value& app_list) override; 44 void OnLoadError() override; 45 void OnParseResponseError() override; 46 47 private: 48 // Records a result value - `loaded_apps_`, if any, should be set before 49 // calling this. 50 void SetResult(Result result); 51 52 // The last result reported by the RecommendAppsFetcher. 53 Result result_ = Result::UNKNOWN; 54 55 // The last reported list of apps reported by the RecommendAppsFetcher. Set 56 // only on LoadSuccess. 57 base::Value loaded_apps_; 58 59 // The callback that will be called when the result is set - used to implement 60 // WaitForResult(). 61 base::OnceClosure result_callback_; 62 }; 63 64 } // namespace chromeos 65 66 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_RECOMMEND_APPS_FAKE_RECOMMEND_APPS_FETCHER_DELEGATE_H_ 67