Skip to content

Commit d3eb7d1

Browse files
Grisha Kruglovgrigoryk
Grisha Kruglov
authored andcommitted
Add concept-storage with a basic history storage interface
1 parent f962f6c commit d3eb7d1

File tree

7 files changed

+149
-0
lines changed

7 files changed

+149
-0
lines changed

automation/taskcluster/artifacts.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
public/build/concept.engine.maven.zip:
2626
path: /build/android-components/components/concept/engine/build/target.maven.zip
2727
name: concept-engine
28+
public/build/concept.storage.maven.zip:
29+
path: /build/android-components/components/concept/storage/build/target.maven.zip
30+
name: concept-storage
2831
public/build/concept.toolbar.maven.zip:
2932
path: /build/android-components/components/concept/toolbar/build/target.maven.zip
3033
name: concept-toolbar

components/concept/storage/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# [Android Components](../../../README.md) > Concept > Storage
2+
3+
The `concept-storage` component contains interfaces and abstract classes that describe a "core data" storage layer.
4+
5+
This abstraction makes it possible to build components that work independently of the storage layer being used.
6+
7+
Currently an [in-memory storage implementation](../../browser/storage-memory) is available.
8+
9+
## Usage
10+
11+
### Setting up the dependency
12+
13+
Use Gradle to download the library from [maven.mozilla.org](https://maven.mozilla.org/) ([Setup repository](../../../README.md#maven-repository)):
14+
15+
```Groovy
16+
implementation "org.mozilla.components:concept-storage:{latest-version}"
17+
```
18+
19+
### Integration
20+
21+
One way to interact with a `concept-storage` component is via [feature-storage](../../features/storage/README.md), which provides "glue" implementations that make use of storage. For example, a `features.storage.HistoryTrackingFeature` allows a `concept.engine.Engine` to keep track of visits and page meta information.
22+
23+
## License
24+
25+
This Source Code Form is subject to the terms of the Mozilla Public
26+
License, v. 2.0. If a copy of the MPL was not distributed with this
27+
file, You can obtain one at http://mozilla.org/MPL/2.0/
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
apply plugin: 'com.android.library'
6+
apply plugin: 'kotlin-android'
7+
8+
android {
9+
compileSdkVersion Config.compileSdkVersion
10+
11+
defaultConfig {
12+
minSdkVersion Config.minSdkVersion
13+
targetSdkVersion Config.targetSdkVersion
14+
}
15+
16+
buildTypes {
17+
release {
18+
minifyEnabled false
19+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20+
}
21+
}
22+
}
23+
24+
dependencies {
25+
implementation Deps.kotlin_stdlib
26+
implementation Deps.support_annotations
27+
28+
// We expose this as API because we are using Observable in our public API and do not want every
29+
// consumer to have to manually import "base".
30+
api project(':support-base')
31+
32+
testImplementation Deps.testing_junit
33+
testImplementation Deps.testing_robolectric
34+
testImplementation Deps.testing_mockito
35+
36+
testImplementation project(':support-test')
37+
}
38+
39+
apply from: '../../../publish.gradle'
40+
ext.configurePublish(Config.componentsGroupId, archivesBaseName, gradle.componentDescriptions[archivesBaseName])
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!-- This Source Code Form is subject to the terms of the Mozilla Public
2+
- License, v. 2.0. If a copy of the MPL was not distributed with this
3+
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
4+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
5+
package="mozilla.components.concept.storage" />
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
package mozilla.components.concept.storage
6+
7+
/**
8+
* An interface which defines read/write methods for history data.
9+
*/
10+
interface HistoryStorage {
11+
/**
12+
* Records a visit to a page.
13+
* @param uri of the page which was visited.
14+
* @param visitType type of the visit, see [VisitType].
15+
*/
16+
fun recordVisit(uri: String, visitType: VisitType)
17+
18+
/**
19+
* Records an observation about a page.
20+
* @param uri of the page for which to record an observation.
21+
* @param observation a [PageObservation] which encapsulates meta data observed about the page.
22+
*/
23+
fun recordObservation(uri: String, observation: PageObservation)
24+
25+
/**
26+
* Maps a list of page URIs to a list of booleans indicating if each URI was visited.
27+
* @param uris a list of page URIs about which "visited" information is being requested.
28+
* @param callback will be invoked with a list of booleans indicating visited status of each
29+
* corresponding page URI from [uris].
30+
*/
31+
fun getVisited(uris: List<String>, callback: (List<Boolean>) -> Unit)
32+
33+
/**
34+
* Retrieves a list of all visited pages.
35+
* @param callback will be invoked with a list of all visited page URIs.
36+
*/
37+
fun getVisited(callback: (List<String>) -> Unit)
38+
}
39+
40+
data class PageObservation(val title: String?)
41+
42+
/**
43+
* Visit type constants as defined by Desktop Firefox.
44+
*/
45+
@SuppressWarnings("MagicNumber")
46+
enum class VisitType(val type: Int) {
47+
// User followed a link.
48+
LINK(1),
49+
// User typed a URL or selected it from the UI (autocomplete results, etc).
50+
TYPED(2),
51+
RELOAD(9)
52+
}

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ setupProject(':concept-awesomebar', 'components/concept/awesomebar', 'An abstrac
2222
setupProject(':concept-toolbar', 'components/concept/toolbar', 'An abstract definition of a toolbar component.')
2323
setupProject(':concept-tabstray', 'components/concept/tabstray', 'An abstract definition of a tabs tray component.')
2424
setupProject(':concept-engine', 'components/concept/engine', 'An abstract layer hiding the actual browser engine implementation.')
25+
setupProject(':concept-storage', 'components/concept/storage', 'An abstract definition of a browser storage layer.')
2526

2627
////////////////////////////////////////////////////////////////////////////////////////////////////
2728
// Features

0 commit comments

Comments
 (0)