blob: 83e9e7a5eb706e0712b5342b70a2751fb89320cc [file] [log] [blame]
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef COBALT_BROWSER_SPLASH_SCREEN_CACHE_H_
#define COBALT_BROWSER_SPLASH_SCREEN_CACHE_H_
#include <string>
#include "base/memory/scoped_ptr.h"
#include "base/optional.h"
#include "base/synchronization/lock.h"
#include "googleurl/src/gurl.h"
namespace cobalt {
namespace browser {
// SplashScreenCache saves a splash screen document loaded by the
// HTMLLinkElement into the system cache, if any, so that it's
// available to BrowserModule to show on subsequent runs before
// loading the initial URL. The key for the cached document is based
// on the passed in initial URL. See cobalt/doc/splash_screen.md for
// more information.
class SplashScreenCache {
public:
SplashScreenCache();
// Cache the splash screen.
bool CacheSplashScreen(const std::string& key,
const std::string& content) const;
// Read the cached the splash screen.
int ReadCachedSplashScreen(const std::string& key,
scoped_array<char>* result) const;
// Determine if a splash screen is cached corresponding to the key.
bool IsSplashScreenCached(const std::string& key) const;
// Get the key that corresponds to a starting URL. Optionally create
// subdirectories along the path.
static base::optional<std::string> GetKeyForStartUrl(const GURL& url);
private:
// Lock to protect access to the cache file.
mutable base::Lock lock_;
};
} // namespace browser
} // namespace cobalt
#endif // COBALT_BROWSER_SPLASH_SCREEN_CACHE_H_